3

我的 StructureMap 配置如下所示:

container.Configure(x => x.For<IStreamWrap>().Use<FileStreamWrap>().SelectConstructor(() => new FileStreamWrap("", System.IO.FileMode.Open));

我正在尝试获取一个实例FileStreamWrap并传入两个参数:

stream = container.With("path").EqualTo(path).With("mode").EqualTo(System.IO.FileMode.Open).GetInstance<IStreamWrap>();

但是我收到此消息的异常,我不知道为什么 StructureMap 仍然选择具有最多参数的构造函数,因为我明确告诉它使用带有两个参数的构造函数(FileStreamWrap(string path, System.IO.FileMode mode)

Unable to create a build plan for concrete type SystemWrapper.IO.FileStreamWrap

new FileStreamWrap(String path, FileMode mode, FileSystemRights rights, FileShare share, Int32 bufferSize, FileOptions options, FileSecurity)
  ┣ String path = Value: path
  ┣ FileMode mode = Value: Open
  ┣ FileSystemRights rights = Required primitive dependency is not explicitly defined
  ┣ FileShare share = Required primitive dependency is not explicitly defined
  ┣ Int32 bufferSize = Required primitive dependency is not explicitly defined
  ┣ FileOptions options = Required primitive dependency is not explicitly defined
  ┗ FileSecurity = **Default**

任何建议将不胜感激。

4

0 回答 0