-
Notifications
You must be signed in to change notification settings - Fork 0
Dealing with dependency injection.
Philemon Eichin edited this page Jun 11, 2018
·
1 revision
You can use a settings service in a depency injection enviroment. For Unity exists an extension that allows you to inject settings into a class.
First you have to configure your container in a way, that it will resolve settings
UnityContainer container = new Unitycontainer();
// ...
container.AddNew<phirSOFT.SettingsService.Unity.SettingsServiceContainerExtension>
// ...
// Register your settings service to the container.
container.RegisterType<ISettingsService, MySettingsService>();
// Register readonly mapping
container.RegisterType<IReadOnlySettingsService, ISettingsService>();
It is importend to register the IReadOnlySettingsService
type, since the resolution only depends on that service.
Now you can use retrive settings in your class
class Foo
{
public Foo([SettingValue("bar")]Bar bar)
{
}
}