0

ninject我有這樣的代碼:C#Ninject到結構圖轉換器

var resourceManagers = new ResourceManager[1]; 
resourceManagers[0] = Validation.ResourceManager; 
kernel.Bind<ILocalizedStringProvider>().To<ResourceStringProvider>() 
    .WithConstructorArgument("resourceManager", resourceManagers); 

kernel.Rebind<ModelValidatorProvider>().To<LocalizedModelValidatorProvider>(); 

我想將其轉換爲StructureMap

我不喜歡這樣的:

IContainer container = new Container(); 
var ioC = new IoC(); 
ioC.Initialize(container); 

container.Configure(x => 
{ 

    var resourceManagers = new ResourceManager[1]; 
    resourceManagers[0] = ModelValidation.ResourceManager; 
    x.For<ILocalizedStringProvider>().Use<ResourceStringProvider>.Ctor<string>(@"resourceManager").Is(resourceManagers); 
    x.For<ModelValidatorProvider>().Add<LocalizedModelValidatorProvider>(); 
}); 

DependencyResolver.SetResolver(new StructureMapDependencyResolver(container)); 
GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver(container); 

,但我得到例外:

硒真實性的代碼說明項目文件的線路抑制狀態 錯誤CS0119「CreatePluginFamilyExpression.Use()」 是一種方法,它是無效的在給定上下文

如何使用StructureMap做到這一點?

回答

1

使用(),因爲是這樣的方法

var resourceManagers = new ResourceManager[1]; 
resourceManagers[0] = ModelValidation.ResourceManager; 

x.For<ILocalizedStringProvider>().Use<ResourceStringProvider>().Ctor<ResourceManager[]> (@"resourceManager").Is(resourceManagers); 
x.For<ModelValidatorProvider>().Add<LocalizedModelValidatorProvider>(); 
1

作爲錯誤消息指出,這樣的:

.Use<ResourceStringProvider>

應該是:

.Use<ResourceStringProvider>()

因爲它是一種方法。