Skip to content

Instantly share code, notes, and snippets.

Created June 2, 2014 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/25c1bb209b94619b5346 to your computer and use it in GitHub Desktop.
Save anonymous/25c1bb209b94619b5346 to your computer and use it in GitHub Desktop.
Auto-registering nested generics with Castle Windsor
public interface IFirestarter<T> { }
public class ConcreteFirestarter<T> : IFirestarter<T> { }
public interface IWaterstarter<T> { }
public class Nestling<T> { }
public class ConcreteWaterstarter<T> : IWaterstarter<Nestling<T>> { }
void CompositionRoot()
{
var container = new WindsorContainer();
container.Register(
Classes
.FromThisAssembly()
.WithService.FirstInterface());
// this works
var myFirestarter
= container.Resolve<IFirestarter<int>>();
// how to make this work?
var myWaterstarterYouTroubleStarter
= container.Resolve<IWaterstarter<Nestling<int>>>();
}
@chilversc
Copy link

It appears Castle Windsor doesn't know how to go from Nestling to just T when resolving the concrete type, it just want's to perform a straight mapping.

But Castle Windsor does provide an interface to control this mapping, see http://kozmic.net/2013/07/24/on-castle-windsor-and-open-generic-component-arity/

As a quick example see http://gist.github.com/chilversc/f42d89ed1b476aa769f3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment