What is Component-Driven Development?

What is it? I think the definition in your answer covers this question well. Although, I question why the definition includes that a component needs to explicitly define its dependencies. A canonical example of a component is an ActiveX control – do they need to explicitly define their dependencies? What problems does it solve? Management … Read more

SqlException from Entity Framework – New transaction is not allowed because there are other threads running in the session

After much pulling out of hair I discovered that the foreach loops were the culprits. What needs to happen is to call EF but return it into an IList<T> of that target type then loop on the IList<T>. Example: IList<Client> clientList = from a in _dbFeed.Client.Include(“Auto”) select a; foreach (RivWorks.Model.NegotiationAutos.Client client in clientList) { var … Read more

Which .NET Dependency Injection frameworks are worth looking into? [closed]

edit (not by the author): There is a comprehensive list of IoC frameworks available at https://github.com/quozd/awesome-dotnet/blob/master/README.md#ioc: Castle Windsor – Castle Windsor is best of breed, mature Inversion of Control container available for .NET and Silverlight Unity – Lightweight extensible dependency injection container with support for constructor, property, and method call injection Autofac – An addictive … Read more

Using IoC for Unit Testing

Generally speaking, a DI Container should not be necessary for unit testing because unit testing is all about separating responsibilities. Consider a class that uses Constructor Injection public MyClass(IMyDependency dep) { } In your entire application, it may be that there’s a huge dependency graph hidden behind IMyDependency, but in a unit test, you flatten … Read more

What is a composition root in the context of dependency injection?

The composition root is the single place in your application where the composition of the object graphs for your application take place, using the dependency injection container (although how this is done is irrelevant, it could be using a container or could be done manually using pure DI). There should only be one place where … Read more

Why do I need an IoC container as opposed to straightforward DI code? [closed]

Wow, can’t believe that Joel would favor this: var svc = new ShippingService(new ProductLocator(), new PricingService(), new InventoryService(), new TrackingRepository(new ConfigProvider()), new Logger(new EmailLogger(new ConfigProvider()))); over this: var svc = IoC.Resolve<IShippingService>(); Many folks don’t realize that your dependencies chain can become nested, and it quickly becomes unwieldy to wire them up manually. Even with factories, … Read more

Why not use an IoC container to resolve dependencies for entities/business objects?

The first question is the most difficult to answer. Is it bad practice to have Entities depend on outside classes? It’s certainly not the most common thing to do. If, for example, you inject a Repository into your Entities you effectively have an implementation of the Active Record pattern. Some people like this pattern for … Read more