views:

154

answers:

1

This is what my service contructor looks like:

public Service(string path)

and I'm configuring unity like this:

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

which of course is not correct. The path parameter needs to be specified, and I would like this to be configurable from the AppSettings so in this case I would be able to set it during configuration.

How do I do this?

+2  A: 

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

This can be done like this:

// Get path from app.config via ConfigurationManager.AppSettings

var container = new UnityContainer();
container.RegisterType<IService, Service>(new InjectionConstructor(path));
Mark Seemann
Exactly what I need. As a follow up, what if I have two parameters, one that can be resolved with a RegisterInstance, and this path parameter?
Dave Van den Eynde
In that case you should be able to use `ResolvedParameter<T>`.
Mark Seemann
@Mark Exactly what I was looking for.
Paul Fryer