-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Address API review feedback about DI integration (#4023)
- Replaces WithServices/WithPlugins callback-based methods with Services/Plugins properties. It makes it less fluent, but it brings it into line with the current best-practices patterns used by ASP.NET, it reduces nesting, it avoids confusion about when the callbacks are invoked, it avoids async-related issues, and it makes the pre-Build syntax for adding plugins to the builder much closer to the post-Build syntax for adding plugins to the Kernel. - Plugins added as services are now automatically resolved as part of Kernel construction. The Kernel will prefer to use a collection it's explicitly handed, but if it isn't given one, it'll try to fetch a collection from the services, and if it can't find that, it'll try to fetch all IKernelPlugins from the services. - Renamed With methods to Add methods to improve parity both with current ASP.NET practices as well as between when doing `builder.AddXx` and `builder.Services.AddXx`. - Renamed `AddPluginFromObject<T>` to `AddFromType<T>`. - Remove `new()` constraint from `AddFromType<T>` and instead use ActivatorUtilities.CreateInstance. The KernelBuilder.Plugins property contains the same IServiceCollection as the builder, and so `AddFromType<T>` has access to it and can use it with CreateInstance to resolve any plugin object ctor arguments from the service provider. For example, HttpPlugin has a ctor that takes an HttpClient, so now doing `builder.Plugins.AddFromType<HttpPlugin>()` will find an HttpClient in the container and use it automatically when the plugins are built as part of Build. - Removed WithLoggerFactory and WithCulture. The latter is basically never used, and it's much more like the Data property and event handlers on the Kernel, where it can easily be mutated on the Kernel instance and doesn't need any builder support. WithLoggerFactory was used a lot, but mainly because of the patterns employed in the tests, and it's easily replacable with AddLogging. - Added IKernelBuilder interface. It's implemented by KernelBuilder and returned from a new AddKernel extension method on IServiceCollection, adding a singleton KernelPluginCollection and a transient Kernel to the container. IKernelBuilder has both the Services and Plugins properties, and also has Build, but Build throws an exception if it's used on the instance returned from AddKernel, per feedback that it can lead to folks accidentally building the container multiple times. - Changed all of the extensions on KernelBuilder to instead by on IKernelBuilder. @davidfowl, @halter73, please ensure this is in line with your feedback. Thanks! --------- Co-authored-by: Mark Wallace <[email protected]> Co-authored-by: SergeyMenshykh <[email protected]>
- Loading branch information
1 parent
7eaa708
commit aa45ee6
Showing
86 changed files
with
1,136 additions
and
1,214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.