Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix child resolve for types with generic interfaces #141

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/TinyIoC/TinyIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3716,23 +3716,26 @@ private ObjectFactoryBase GetParentObjectFactory(TypeRegistration registration)

ObjectFactoryBase factory;

if (_Parent._RegisteredTypes.TryGetValue(registration, out factory))
{
return factory.GetFactoryForChildContainer(registration.Type, _Parent, this);
}

#if RESOLVE_OPEN_GENERICS
// Attempt container resolution of open generic
if (registration.Type.IsGenericType())
{
var openTypeRegistration = new TypeRegistration(registration.Type,
var openTypeRegistration = new TypeRegistration(registration.Type.GetGenericTypeDefinition(),
registration.Name);

if (_Parent._RegisteredTypes.TryGetValue(openTypeRegistration, out factory))
{
return factory.GetFactoryForChildContainer(openTypeRegistration.Type, _Parent, this);
return factory.GetFactoryForChildContainer(registration.Type, _Parent, this);
}

return _Parent.GetParentObjectFactory(registration);
}

if (_Parent._RegisteredTypes.TryGetValue(registration, out factory))
{
return factory.GetFactoryForChildContainer(registration.Type, _Parent, this);
}
#endif

return _Parent.GetParentObjectFactory(registration);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TinyIoC.Tests/TinyIoC.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<PropertyGroup>
<DefineConstants>TRACE;MOQ</DefineConstants>
<DefineConstants>TRACE;MOQ;RESOLVE_OPEN_GENERICS</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions tests/TinyIoC.Tests/TinyIoCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

#region Preprocessor Directives

// Skip open generics tests on platforms that don't support it
#if PocketPC || NETFX_CORE
#undef RESOLVE_OPEN_GENERICS
#endif

#endregion

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down