Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency Injection in .net core, Autofac vs StructureMap vs Factory Method to resolve interface if registered with multiple implementation

In my project I using chain of responsibility designing pattern for which I need to create multiple handlers which will implement same interface. In .net application(not .net core) I would have used DI using UnityContainer where I could have resolved handlers using named parameter. But in .net core I can not do that. Now I have few options to use other DI libraries like Autofac, Structuremap or create factory method which can give me objects based on name passed. Please help me in picking right approach between these or suggest something better if available. I have not used Autofac or Structuremap so I very little idea of same. Thanks.

like image 828
Rakesh Avatar asked Jan 29 '23 01:01

Rakesh


1 Answers

For the most part, all DI tools out there achieve the same thing with different APIs. These days the differences are highlighted by your needs.

StructureMap or Autofac are both good candidates. It all boils down to "flavor".

Check this article. I think is a good one. Configuration comparison dependency injection containers

Again, don't stress over them unless you need a very very specific feature form one of them.

I would do Autofac just because I haven't had the need for something else however, I would not hesitate to use StructureMap, Ninject or whatever new kid on the block is brought up.

like image 113
Pepito Fernandez Avatar answered Jan 31 '23 19:01

Pepito Fernandez