Wonderful Microsoft.Extensions.DependencyInjection.IServiceCollection
has a lot of extensions associated with it.
One example is Microsoft.Extensions.Logging.ConsoleLoggerExtensions
and AddConsole(this ILoggingBuilder builder)
method which registers ConsoleLoggerProvider
in ILoggingBuilder.Services
property of type IServiceCollection
.
So, the logical question for anyone using Autofac. How to re-use all this extensions? Is there's a way to convert all IServiceCollection
registrations to ContainerBuilder
registrations?
Getting Microsoft.Extensions.DependencyInjection
registrations into Autofac is the whole point of the Autofac.Extensions.DependencyInjection
package. That's the integration for Autofac with .NET Core. There is plenty of doc and examples on how to get going.
By the way, this sort of adapter pattern isn't specific to Autofac. This conversion sort of thing is how most of the other DI frameworks back the conforming container in Microsoft.Extensions.DependencyInjection
. If you happen to switch away from Autofac for some reason, check out the docs on those frameworks because they all have some sort of integration library.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.