2009-07-07 53 views
0

我試圖用流利的接口註冊下列類別的具體類型的組件:註冊,需要一個構造函數參數,那就是沒有接口

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)); 

回答

1

明白了!

_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") 
          }) 
       ); 
+0

是的,正好。 – 2009-07-08 07:27:27

相關問題