Skip to content

Instantly share code, notes, and snippets.

@kkozmic
Created September 6, 2011 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 ?
@ploeh
Copy link

ploeh commented Sep 6, 2011

Without having pondered this extensively, I'd expect an exception to be thrown. I'd expect ResolveAll<IFoo<string>> to return instances of SimpleFoo<string> and FooWithBar<string> - however FooWithBar<string> is waiting for dependencies to be satisfied, as there are no registrations of IBar<string>.

@chaliy
Copy link

chaliy commented Sep 6, 2011

Code should explode so guy who made this code will get as much damage as possible.
1.StructOnlyFoo should not return of course, this is silently.
2.FooWithBar could be return, so Windsor should cry with as much details as you have, because this will be really hard to find an issue like this.

So as results ResolveAll should throw an exception.

@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