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

Translate ninject ISecureDataFormat binding to Autofac

The migration from Ninject to Autofac seems to be correct, but the binding for the ISecureDataFormat<AuthenticationTicket> interface may not be working as expected, leading to an activation error in some dependencies. Based on the debugging messages, the BearerTokenCookieStore class is failing to resolve this dependency. In the Ninject version, ISecureDataFormat<AuthenticationTicket> is bound to a method … Read more

Dependency Inversion Principle (SOLID) vs Encapsulation (Pillars of OOP)

Does IoC always break encapsulation, and therefore OOP? No, these are hierarchically related concerns. Encapsulation is one of the most misunderstood concepts in OOP, but I think the relationship is best described via Abstract Data Types (ADTs). Essentially, an ADT is a general description of data and associated behaviour. This description is abstract; it omits … Read more

IoC.Resolve vs Constructor Injection

IoC.Resolve<> is an example of the Service Locator pattern. That pattern imposes a few restrictions that constructor injection does not: Objects can have no more fine-grained context than the application domain, due to the static calls Objects decide which versions of dependencies to resolve. All instances of a certain class will get the same dependency … Read more

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

Simple Injector vs Hiro vs Autofac [closed]

Let me start by saying that I’m the lead developer behind Simple Injector. I agree with Mark that in most cases performance of a container isn’t a problem. Still, some containers perform very poor at some points and it can be hard to intuitively sense what parts of the configuration can be problematic from a … Read more

Difference between MEF and IoC containers (like Unity, Autofac, SMap, Ninject, Windsor.Spring.net, etc.)

Eventually what I have concluded about the MEF vs IoC container is as follows: MEF is preferred to be used when one has to deal with unknown types or a plugin based architecture. IoC containers are preferred to be used with known types. Moreover, MEF is an architectural solution for dependency injection Whereas, IoC containers … Read more

Abstractions should not depend upon details. Details should depend upon abstractions?

It means that if the details change they should not affect the abstraction. The abstraction is the way clients view an object. Exactly what goes on inside the object is not important. Lets take a car for example, the pedals and steering wheel and gear lever are abstractions of what happens inside the engine. They … Read more

NInject: Where do you keep your reference to the Kernel?

It’s true that you don’t want to pass around the kernel. Typically, in a web app, I store the kernel in a static property in the HttpApplication. If you need a reference to the kernel, you can just expose a dependency (via constructor argument or property) that is of the type IKernel, and Ninject will … Read more

Design – Where should objects be registered when using Windsor [closed]

In general, all components in an application should be composed as late as possible, because that ensures maximum modularity, and that modules are as loosely coupled as possible. In practice, this means that you should configure the container at the root of your application. In a desktop app, that would be in the Main method … Read more