Dav*_*nde 5 .net dependency-injection unity-container
这就是我的服务构造器的样子:
public Service(string path)
Run Code Online (Sandbox Code Playgroud)
我正在配置像这样的团结:
IUnityContainer container = new UnityContainer();
container.RegisterType<IService, Service>();
Run Code Online (Sandbox Code Playgroud)
这当然是不正确的.需要指定path参数,我希望可以从AppSettings配置它,所以在这种情况下我可以在配置期间设置它.
我该怎么做呢?
据我所知,您希望从AppSetting中读取路径,然后以编程方式配置UnityContainer.
这可以这样做:
// Get path from app.config via ConfigurationManager.AppSettings
var container = new UnityContainer();
container.RegisterType<IService, Service>(new InjectionConstructor(path));
Run Code Online (Sandbox Code Playgroud)