注册,需要一个构造函数参数,那就是没有接口
问题描述:
我试图用流利的接口注册下列类别的具体类型的组件:注册,需要一个构造函数参数,那就是没有接口
public class DirectorySync : IDirectorySync
{
public DirectorySync(DirectoryInfo sourceDir, DirectoryInfo targetDir)
{
_sourceDirectory = sourceDir;
_targetDirectory = targetDir;
}
}
如何去指定的DirectoryInfo实例?他们应该是:
var sourceDirectory = new DirectoryInfo("some known file path");
var installationDirectory = new DirectoryInfo("some other known file path");
这是我到目前为止有:
_container.Register(Component
.For<IDirectorySync>()
.ImplementedBy<DirectorySync>()
.Parameters(Parameter.ForKey("sourceDir").Eq(???))
.Parameters(Parameter.ForKey("targetDir").Eq(???))
.LifeStyle.Is(LifestyleType.Transient));
答
明白了!
_container.Register(Component
.For<IDirectorySync>()
.ImplementedBy<DirectorySync>()
.LifeStyle.Is(LifestyleType.Transient)
.DependsOn(new
{
sourceDir = new DirectoryInfo("some known file path"),
targetDir = new DirectoryInfo("some other known file path")
})
);
是的,正好。 – 2009-07-08 07:27:27