简体   繁体   中英

Autofac - Can I use Microsoft.Extensions.DependencyInjection's Registering Style instead of Autofac one?

We know that the registering style should look like builder.RegisterType<EmailService1>().As<ISendEmailService>().SingleInstance(); while asp.net core built-in uses services.AddSingleton<ISendEmailService, EmailService1>();

I wonder if we can keep the built-in style and use Autofac as DI engine? I have a project used to use asp.net core built-in DI [Microsoft.Extensions.DependencyInjection], we want to swtich to Autofac without rewriting all register codes from built-in one to Autofac one. Is it possible?

ps I have installed Autofac.Extensions.DependencyInjection and set up as document mentioned

Yes, you can do all your registrations using Microsoft format of you like. Just don't try to use both syntaxes in the same registration - like if you are registering a lambda registration in Microsoft format, you can't use Autofac stuff in that lambda.

Your best way to find out if something like this is possible is to just do it. Try a little POC. You may run into things that are app-specific that don't work for one reason or another. That's not something anyone out here can predict.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM