I'm migrating my site, from asp.net 4.5 to 5.0. Previously, I used System.Web.Mvc to get DependencyResolver.SetResolve to register dependencies. Is there any publication or documentation that can point me to the new Microsoft.AspNet.Mvc version?
Asked
Active
Viewed 2,867 times
0
nruim83
- 41
- 1
- 5
1 Answers
2
http://docs.asp.net/en/latest/fundamentals/dependency-injection.html
That's official documentation for dependency injection for asp.net 5.
Dependency injection is now built into asp.net 5 but you are free to use other libraries like autofac. The default one is working fine for me.
In your starup class, you have a method like this
public void ConfigureServices(IServiceCollection services)
{
//IServiceCollection acts like a container and you
//can register your classes like this:
services.AddTransient<IEmailSender, AuthMessageSender>();
services.Singleton<ISmsSender, AuthMessageSender>();
services.AddScoped<ICharacterRepository, CharacterRepository>();
}
These are some Service Lifetimes and Registration Options
Bilal Fazlani
- 6,727
- 9
- 44
- 90
-
`protected virtual void RegisterDependencies(QuizConfig config) { var builder = new ContainerBuilder(); var container = builder.Build(); **DependencyResolver.SetResolver(new AutofacDependencyResolver(container));** }` This is in a Library. – nruim83 Dec 12 '15 at 11:03
-
What library ? I dont understand what you are trying to say – Bilal Fazlani Dec 12 '15 at 19:00
-
I created a library, that my main project uses. – nruim83 Dec 12 '15 at 21:17