Skip to content

Instantly share code, notes, and snippets.

@kkozmic
Created September 6, 2011 10:57
Show Gist options
  • Save kkozmic/1197260 to your computer and use it in GitHub Desktop.
Save kkozmic/1197260 to your computer and use it in GitHub Desktop.
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 ?
@HEskandari
Copy link

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.

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