How to configure Unity to apply a "constant" string to a constructor parameter during RegisterType ()?

Here's what my maintenance constructor looks like:

public Service(string path) 

and I configure it as follows:

 IUnityContainer container = new UnityContainer(); container.RegisterType<IService, Service>(); 

which of course is not true. You must specify a path parameter, and I would like it to be configured from AppSettings, so in this case I could set it during configuration.

How to do it?

+4
source share
1 answer

As I understand your question, you want to read the path from AppSetting and then programmatically configure your UnityContainer.

This can be done as follows:

 // Get path from app.config via ConfigurationManager.AppSettings var container = new UnityContainer(); container.RegisterType<IService, Service>(new InjectionConstructor(path)); 
+7
source