views:

46

answers:

1

I am trying to register the following class using the fluent interface:

public class DirectorySync : IDirectorySync
{
  public DirectorySync(DirectoryInfo sourceDir, DirectoryInfo targetDir)
  {
    _sourceDirectory = sourceDir;
    _targetDirectory = targetDir;
  }
}

How do I go about specifying the DirectoryInfo instances? They should be:

var sourceDirectory = new DirectoryInfo("some known file path");
var installationDirectory = new DirectoryInfo("some other known file path");

This is what I have so far:

_container.Register(Component
  .For<IDirectorySync>()
  .ImplementedBy<DirectorySync>()
  .Parameters(Parameter.ForKey("sourceDir").Eq(???))
  .Parameters(Parameter.ForKey("targetDir").Eq(???))
  .LifeStyle.Is(LifestyleType.Transient));
+1  A: 

Got it!

_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")
                           })
                );
KevinT
Yes, precisely.
Krzysztof Koźmic