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 #137

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why this was moved out? It would be nice to have additional test coverage for any changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
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
6 changes: 6 additions & 0 deletions tests/TinyIoC.Tests/TinyIoCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

#region Preprocessor Directives

#define RESOLVE_OPEN_GENERICS // Platform supports resolving open generics
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this get moved to the csproj

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #141


#endregion

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