Created
September 6, 2011 10:57
-
-
Save kkozmic/1197260 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 IFoo<T> | |
{} | |
public class SimpleFoo<T>: IFoo<T> | |
{} | |
public class StructOnlyFoo<T>: IFoo<T> where T : struct | |
{} | |
public class FooWithBar<T>:IFoo<T> | |
{ | |
public FooWithBar(IBar<T> bar){} | |
} | |
public interface IBar<T> | |
{} | |
public class DefaultCtorBar<T>: IBar<T> where T: new() | |
{} | |
// now you register all those classes in the container as their respective interfaces, in open generic version | |
// and then call container.ResolveAll<IFoo<String>>(); // notice string is not a struct and does not have public parameterless constructor | |
// | |
// what should happen ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems we can only create SimpleFoo<T> as FooWithBar<T> is depending an IBar<T> and DefaultCtorBar<T> can not be used for strings (no public ctor) and StructOnlyFoo is also out of question for strings. What I expect would be an exception though (unless all IFoo<T> implementations can be resolved successfully using ResolveAll). Given there is a Resolve<IFoo<string>> which returns just one implementation and there is one implementation that can be constructed, I expect it to return SimpleFoo<string> instead of throwing exceptions.