Examples of IoC Containers [closed]

I’ve used StructureMap quite a bit. The rest of your question is pretty loaded. I’ll try to explain the concept in an example. Suppose you created a website that will accept payments through PayPal. PayPal is now a dependency. But you don’t want to code against a specific PayPal provider. Instead, you would create and … Read more

How do I control MembershipProvider instance creation/lifetime?

I just blogged about this with a solution. In a nutshell, this solution involves a simple, reusable MembershipProvider that calls the container to resolve your custom MembershipProviders. Unlike other solutions that use “BuildUp” container features, this one takes true control of instantiation, thus enabling constructor injection (which in turn enables immutability) and proxyability.

Exception is: InvalidOperationException – The current type, is an interface and cannot be constructed. Are you missing a type mapping?

Just for others (like me) who might have faced the above error. The solution in simple terms. You might have missed to register your Interface and class (which implements that inteface) registration in your code. e.g if the error is “The current type, xyznamespace. Imyinterfacename, is an interface and cannot be constructed. Are you missing … Read more

MEF (Managed Extensibility Framework) vs IoC/DI

The principle purpose of MEF is extensibility; to serve as a ‘plug-in’ framework for when the author of the application and the author of the plug-in (extension) are different and have no particular knowledge of each other beyond a published interface (contract) library. Another problem space MEF addresses that’s different from the usual IoC suspects, … Read more

How to use a DI / IoC container with the model binder in ASP.NET MVC 2+?

A couple of observations: Don’t inject dependencies just to query them in the constructor There’s no reason to inject an ITimeProvider into a user just to invoke Now immediately. Just inject the creation time directly instead: public User(DateTime creationTime) { this.CreationTime = creationTime; } A really good rule of thumb related to DI is that … Read more