Skip to content

Commit

Permalink
fix generic bulk ByInteface problem for issue #148
Browse files Browse the repository at this point in the history
  • Loading branch information
ipjohnson committed Jan 30, 2018
1 parent 56b8bf2 commit 4b64311
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Grace/DependencyInjection/Impl/ExportTypeSetConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public ExportTypeSetConfiguration(IActivationStrategyCreator strategyCreator, IE
_scopeConfiguration = scopeConfiguration;
_whereFilter = new GenericFilterGroup<Type>(ShouldSkipType, ExcludeTypesFilter);
}



/// <summary>
/// Add conditions for export
/// </summary>
Expand Down Expand Up @@ -342,6 +341,11 @@ private IEnumerable<ICompiledExportStrategy> CreateExportStrategiesForTypes(Type
{
foreach (var type in types)
{
if (!type.GetTypeInfo().DeclaredConstructors.Any(c => c.IsPublic && !c.IsStatic && !c.IsAbstract))
{
continue;
}

var exportTypes = GetExportedTypes(type);
var keyedExports = GetKeyedExportTypes(type);
var names = GetExportNames(type);
Expand Down Expand Up @@ -576,7 +580,7 @@ private ImmutableLinkedList<Type> GetExportedInterfaceList(Type type)
{
if (exportInterface.GetTypeInfo().IsGenericTypeDefinition)
{
if (implementedInterface.GetTypeInfo().IsGenericTypeDefinition &&
if (implementedInterface.GetTypeInfo().IsGenericType &&
implementedInterface.GetGenericTypeDefinition() == exportInterface)
{
returnList = returnList.Add(type.GetTypeInfo().IsGenericTypeDefinition ? exportInterface : implementedInterface);
Expand Down
40 changes: 40 additions & 0 deletions tests/Grace.Tests/Classes/Simple/CommandClasses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Grace.Tests.Classes.Simple
{
public interface ICommand<T>
{
void DoSomething(T value);
}

public abstract class BaseCommand<T> : ICommand<T>
{
public abstract void DoSomething(T value);
}

public class CommandA : BaseCommand<int>
{
public override void DoSomething(int value)
{

}
}

public class CommandB : BaseCommand<string>
{
public override void DoSomething(string value)
{

}
}

public class CommandC : BaseCommand<double>
{
public override void DoSomething(double value)
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Grace.DependencyInjection;
using Grace.DependencyInjection.Exceptions;
using Grace.DependencyInjection.Lifestyle;
using Grace.Diagnostics;
using Grace.Tests.Classes.Simple;
using Grace.Tests.DependencyInjection.AddOns;
using Xunit;
Expand Down Expand Up @@ -261,6 +262,21 @@ public void ExportTypeSet_ByType()
Assert.Same(instance, instance2);
}

[Fact]
public void ExportTypeSet_Commands()
{
var container = new DependencyInjectionContainer(c => c.SupportFuncType = false);

container.Configure(c =>
{
c.ExportAssemblyContaining<CommandA>().ByInterface(typeof(ICommand<>));
});

var exports = container.StrategyCollectionContainer.GetAllStrategies().ToList();

Assert.Equal(3, exports.Count);
}

[Fact]
public void ExportTypeSet_ByType_With_Filter()
{
Expand Down

0 comments on commit 4b64311

Please sign in to comment.