-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing support for IExportStrategyProviderAttribute issue #283
- Loading branch information
Showing
3 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/Grace.Tests/DependencyInjection/AttributeTests/ExportStrategyProviderAttributeTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Grace.DependencyInjection; | ||
using Grace.DependencyInjection.Attributes.Interfaces; | ||
using Grace.DependencyInjection.Impl; | ||
using Grace.DependencyInjection.Impl.CompiledStrategies; | ||
using Grace.Tests.Classes.Simple; | ||
using Xunit; | ||
|
||
namespace Grace.Tests.DependencyInjection.AttributeTests | ||
{ | ||
public class ExportStrategyProviderAttributeTest | ||
{ | ||
[Fact] | ||
public void ExportMagicAttributeTest() | ||
{ | ||
var container = new DependencyInjectionContainer(); | ||
|
||
container.Configure( | ||
block => block.ExportAssemblyContaining<ExportStrategyProviderAttributeTest>() | ||
.Where(TypesThat.AreInTheSameNamespaceAs<ExportStrategyProviderAttributeTest>()) | ||
.ExportAttributedTypes() | ||
); | ||
|
||
var depService = container.Locate<IDependentService<SomeWrappedTyped>>(); | ||
|
||
Assert.NotNull(depService); | ||
} | ||
} | ||
|
||
public class MagicExportAttribute : Attribute, IExportStrategyProviderAttribute | ||
{ | ||
public ICompiledExportStrategy ProvideStrategy(Type attributedType, IActivationStrategyCreator creator) | ||
{ | ||
var newType = typeof(DependentService<>).MakeGenericType(attributedType); | ||
var exportType = typeof(IDependentService<>).MakeGenericType(attributedType); | ||
|
||
var strategy = creator.GetCompiledExportStrategy(newType); | ||
|
||
strategy.AddExportAs(exportType); | ||
|
||
return strategy; | ||
} | ||
} | ||
|
||
[MagicExport] | ||
public class SomeWrappedTyped | ||
{ | ||
|
||
} | ||
} |