-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Description
Considering the following example:
container.Register(typeof(Foo<>)); // class Foo<T> { }
container.RegisterSingleton(typeof(Bar<>)); // class Bar<T> { }
// Class Consumer<T>(Foo<T> f, Bar<T> b) { }
container.Register<Consumer<int>>();
container.Verify();Verification fails complaining that Bar<int> is not registered.
Reason for this is that the RegisterSingleton overload called is RegisterSingleton(Type openGenericServiceType, params Assembly[] assemblies), which means that the following call is made:
container.RegisterSingleton(openGenericServiceType: typeof(Bar<>), assemblies: new Assembly[0]);This results in the assembly scanning of non-generic implementations of Bar<T> within zero assemblies.
This actually costed me 10 minutes to figure out what was going on. If this happens to me... it can happen to anyone.