File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -3337,6 +3337,22 @@ public void Resolve_RegisteredOpenGeneric_ReturnsInstance()
33373337 }
33383338#endif
33393339
3340+
3341+ #if RESOLVE_OPEN_GENERICS
3342+ [ TestMethod ]
3343+ public void Resolve_RegisteredOpenGenericInParent_CanBeResolvedByChild ( )
3344+ {
3345+ var container = UtilityMethods . GetContainer ( ) ;
3346+ container . Register ( typeof ( IThing < > ) , typeof ( DefaultThing < > ) ) ;
3347+
3348+ var child = container . GetChildContainer ( ) ;
3349+
3350+ var result = child . Resolve < IThing < object > > ( ) ;
3351+
3352+ Assert . IsInstanceOfType ( result , typeof ( DefaultThing < object > ) ) ;
3353+ }
3354+ #endif
3355+
33403356 #region Unregister
33413357
33423358 private readonly ResolveOptions options = ResolveOptions . FailUnregisteredAndNameNotFound ;
Original file line number Diff line number Diff line change @@ -3715,6 +3715,20 @@ private ObjectFactoryBase GetParentObjectFactory(TypeRegistration registration)
37153715 return null ;
37163716
37173717 ObjectFactoryBase factory ;
3718+
3719+ if ( registration . Type . IsGenericType ( ) )
3720+ {
3721+ var openTypeRegistration = new TypeRegistration ( registration . Type . GetGenericTypeDefinition ( ) ,
3722+ registration . Name ) ;
3723+
3724+ if ( _Parent . _RegisteredTypes . TryGetValue ( openTypeRegistration , out factory ) )
3725+ {
3726+ return factory . GetFactoryForChildContainer ( openTypeRegistration . Type , _Parent , this ) ;
3727+ }
3728+
3729+ return _Parent . GetParentObjectFactory ( registration ) ;
3730+ }
3731+
37183732 if ( _Parent . _RegisteredTypes . TryGetValue ( registration , out factory ) )
37193733 {
37203734 return factory . GetFactoryForChildContainer ( registration . Type , _Parent , this ) ;
You can’t perform that action at this time.
0 commit comments