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.

Database injection into a validation attribute with ASP MVC and Castle Windsor

AFAIK no dependency injection container can directly manage an attribute, since it’s instantiated by the runtime and there’s no way to intercept that. However, they can cheat by either: Using a static gateway to the container (example), or Using a “BuildUp” feature that injects whatever dependencies are found within an already-constructed object. This is called … Read more

How to integrate IoC Membership provider with ASP.NET MVC

The simplest way to get this to work is to use ASP.NET’s standard mechanism of <membership> in web.config. You just let it use the default constructor but you override Initialize() and pull the dependencies there. Use this as reference. Personally, due to things like this, I prefer to avoid the provider model altogether so I … Read more

Resolving HttpControllerContext with Castle Windsor

Just for the sake of completeness, an answer I got from Krzysztof Koźmic (the current maintainer of Castle Windsor) on Twitter indicated that the method outlined in the question is, indeed, the correct way of achieving this particular goal. (However, I can’t link to that tweet, since Krzysztof’s twitter account is protected (tweets are not … Read more

How can I register a generic decorator using Castle Windsor?

currently this is not supported OOTB due to the fact that Windsor always favours mode specific component over an open-generic. You can get that working quite easily with an ISubDependencyResolver though. The code below assumes you name the component for your decorator “DeadlockRetryCommandHandlerDecorator” public class CommandHandlerResolver : ISubDependencyResolver { private readonly IKernel kernel; public FooResolver(IKernel … Read more

Which Dependency Injection Tool Should I Use? [closed]

Having recently spiked the use of 6 of these (Windsor, Unity, Spring.Net, Autofac, Ninject, StructureMap) I can offer a quick summary of each, our selection criteria and our final choice. Note: we did not look at PicoContainer.Net as one of our team considered the .Net port to be quite poor from the Java version. We … Read more