我正在寻找一个 FAST IoC 容器并找到了 Dynamo.IoC。
让它像一个简单的 ServiceLocator 一样工作很容易,但是如何将它用于构造函数注入呢?
这是示例类
private interface ITestInterface
{
}
private class TestClass : ITestInterface
{
}
private class TestClassWithDependency
{
public ITestInterface DependecyInstance { get; private set; }
public TestClassWithDependency( ITestInterface dependencyInstance )
{
DependecyInstance = dependencyInstance;
}
}
和失败的测试
[Test]
public void Test_Container_Resolve_WithDependency()
{
Container.Register<ITestInterface, TestClass>();
var obj = Container.Resolve<TestClassWithDependency>( );
obj.Should().NotBeNull();
obj.DependecyInstance.Should( ).NotBeNull( );
}