Created
June 2, 2014 15:46
-
-
Save anonymous/25c1bb209b94619b5346 to your computer and use it in GitHub Desktop.
Auto-registering nested generics with Castle Windsor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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