With Unity how do I inject a named dependency into a constructor?

You can configure dependencies with or without names in the API, attributes, or via the config file. You didn’t mention XML above, so I’ll assume you’re using the API. To tell the container to resolve a named dependency, you’ll need to use an InjectionParameter object. For your ClientModel example, do this: container.RegisterType<IClientModel, ClientModel>( new InjectionConstructor( … Read more

Do I need dependency injection in NodeJS, or how to deal with …?

In short, you don’t need a dependency injection container or service locater like you would in C#/Java. Since Node.js, leverages the module pattern, it’s not necessary to perform constructor or property injection. Although you still can. The great thing about JS is that you can modify just about anything to achieve what you want. This … Read more

Is there a good/proper way of solving the dependency injection loop problem in the ASP.NET MVC ContactsManager tutorial?

As a general consideration, circular dependencies indicate a design flaw – I think I can safely say this since you are not the original author of the code 🙂 I wouldn’t consider an Initialize method a good solution. Unless you are dealing with an add-in scenario (which you aren’t), Method Injection is not the right … Read more

How to remove unit of work functionality from repositories using IOC

You shouldn’t try to supply the AcmeDataContext itself to the EmployeeRepository. I would even turn the whole thing around: Define a factory that allows creating a new unit of work for the Acme domain: Create an abstract AcmeUnitOfWork that abstracts away LINQ to SQL. Create a concrete factory that can allows creating new LINQ to … Read more

How to use Dependency Injection with ASP.NET Web Forms

UPDATE 2019: With the introduction of Web Forms 4.7.2, there is now better support for DI. This invalidates the below. See: Wiring up Simple Injector in WebForms in .NET 4.7.2 You can use automatic constructor injection by replacing the default PageHandlerFactory with a custom one. This way you can use an overloaded constructor to load … Read more