Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Introduce IStartup interface - #714

Merged
davidfowl merged 1 commit into
devfrom
davidfowl/remove-startup-loader
Apr 19, 2016
Merged

davidfowl merged 1 commit into
devfrom
davidfowl/remove-startup-loader

Conversation

@davidfowl

@davidfowl davidfowl commented Apr 18, 2016 •

Copy link
Copy Markdown
Member

This change introduces a new service IStartup that can be registered in the hosting container to override any startup logic. UseStartup overloads have been changed to detect IStartup and directly put it in the container, or to wrapping it with a ConventionBasedStartup implementation to preserve the existing behavior.

  • Remove IStartupLoader and add IStartup instead that matches the signature hosting cares about
  • Moved UseStartup to extension methods
  • Move existing logic into ConventionBasedStartup class

/cc @Tratcher @JunTaoLuo


namespace Microsoft.AspNetCore.Hosting
{
public abstract class Startup : IStartup

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having Startup as the base name is going to be an obnoxious conflict with app's Startup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StartupBase?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that better

@Tratcher

Copy link
Copy Markdown
Member

How about these?
#712
#333

@Tratcher

Copy link
Copy Markdown
Member

The code is simpler in a few places, but you've added multiple concepts that we now have to explain to people. E.g. The interface, base class, wrapper classes, incompatible Configuration variations, etc. All told I think this is worse for consumers because it will be much more confusing. We need to choose one pattern or the other.

@davidfowl

Copy link
Copy Markdown
Member Author

The code is simpler in a few places, but you've added multiple concepts that we now have to explain to people. E.g. The interface, base class, wrapper classes, incompatible Configuration variations, etc. All told I think this is worse for consumers because it will be much more confusing. We need to choose one pattern or the other.

That's inaccurate, the main change is simplifying the hosting interface between the hosting and the application layer. The new contract is IStartup. Now we can talk about preserving the behavior of the Startup class we have today and determine if we want to keep that separately.

The new classes are:

  • IStartup - Contract for calling the application bootstrapper
  • StartupBase - Convenience base class for end users
  • ConventionBasedStartup - Logic we have today
  • DelegateStartup - Direct delegate to invoke the configure method

I'm going to commit this because it cleans up the hosting code very nicely and doesn't break the existing mechanisms around the Startup pattern. We can figure out how to change the ConventionBasedStartup to do more things like #712 #333 if we choose to later.

@davidfowl davidfowl changed the title Remove Startup magic and introduce IStartup interface Introduce IStartup interface Apr 19, 2016
@davidfowl

Copy link
Copy Markdown
Member Author

@Tratcher Also:

#333 - We get this for free now, you can call AddSingleton<IStartup>(new MyStartup());
#712 - Just a bug, needs to be rebased.

@davidfowl

Copy link
Copy Markdown
Member Author

TBH, we could get rid of the base class and force user code to implement the interface since we already have the convention based startup.

…d in the hosting container to override any startup logic. `UseStartup` overloads have been changed to detect `IStartup` and directly put it in the container, or to wrapping it with a `ConventionBasedStartup` implementation to preserve the existing behavior.

- Remove IStartupLoader and add `IStartup` instead that matches the signature hosting cares about
- Moved `UseStartup` to extension methods
- Move existing logic into `ConventionBasedStartup` class
@divega

divega commented Apr 19, 2016 •

Copy link
Copy Markdown

@davidfowl do we get real public (i.e. Internal namespace doesn't count) surface to resolve the IStartup of the app? A well defined contract should help but we shouldn't be in the business of replicating this logic in design time tools like EF migrations and scaffolding.

@davidfowl

Copy link
Copy Markdown
Member Author

@divega If you use the hosting logic then you have everything in the container, otherwise it's no different than what you have today. Today we still support all of the injection etc via ConventionBasedStartup. It's another discussion if we want to stick to the interface only.

Also, injection is still supported in the ctor of the IStartup so you still need to deal with that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants