Here is the c# code:
var server = ******* some internal logic to determine server name ****
var username = ******* some internal logic to determine user name ****
var password = ******* some internal logic to determine password ****
ObjectFactory.Initialize(x =>
{
x.For<IService<bool>>().Add<Service>()
.Ctor<string>("server").Is(server)
.Ctor<string>("username").Is(username)
.Ctor<string>("password").Is(password)
}
This works great but I would like to move this to configuration file as I开发者_开发问答 don't want to reference to concerete type directly in my code.
There isn't much documentation about 2.6. I couldn't find how to handle this in configuration.
Ideally I would like to inject the server, username, and password paramenters in to ObjectFactory and some how use these parameters in the configuration.
(PS: It doesn't necessary need to be with StructureMap any IAC container that can support this scenario will be welcome.)
Thanks
The simplest way to handle this type of case would be to introduce a new type to provide the primitive constructor args, and register that in code. Then you can register the service, and that new type can be auto wired by the container. This also allows you to move the logic to get the server, username and password into this new object and out of the container configuration.
精彩评论