a***@public.gmane.org
2014-10-09 12:58:50 UTC
Hi,
I haven't seen anything like this that comes as part of Windsor, but
apologies in advance if I've just ended up reinventing the wheel.
I tend to create interfaces for accessing app config settings so that I can
easily mock them when writing unit tests. What I found myself doing was
ending up having to alter a concrete class with boiler plate code each time
I added a new setting to an application, which was starting to get a bit
annoying. So what I ended up doing was creating a Windsor facility that
uses dynamic proxy to automatically implement a settings interface, so I
don't have to update stuff in two places.
For example, say I've got some settings like:
<appSettings>
<add key="Zendesk.Url" value="abc.zendesk.com"/>
<add key="Zendesk.ApiToken" value="aaaaaaaaa"/>
<add key="Git.Email" value="adam-***@public.gmane.org"/>
<add key="Git.Name" value="Adam Connelly"/>
</appSettings>
And a couple of interfaces:
public interface ZendeskConfig
{
string Url { get; }
string ApiToken { get; }
}
public interface GitConfig
{
string Email { get; }
string Name { get; }
}
You can configure your container like this:
var container = new WindsorContainer();
container.AddFacility<AppConfigFacility>();
container.Register(
Component.For<IZendeskConfig>().FromAppConfig(c =>
c.WithPrefix("Zendesk.")),
Component.For<IGitConfig>().FromAppConfig(c => c.WithPrefix("Git."))
);
Then just resolve them / inject them as normal.
It also supports getting the settings from Azure, caching, and computed
properties currently.
The code's available on Github
at https://github.com/adamconnelly/WindsorAppConfigFacility.
What I'm wondering is whether you'd be interested in adding this to
Windsor, and if so, what would I need to change for you to accept it. I'm
more than happy to reformat any files to suit your code format, and make
any changes where I've missed stuff.
Cheers,
Adam
I haven't seen anything like this that comes as part of Windsor, but
apologies in advance if I've just ended up reinventing the wheel.
I tend to create interfaces for accessing app config settings so that I can
easily mock them when writing unit tests. What I found myself doing was
ending up having to alter a concrete class with boiler plate code each time
I added a new setting to an application, which was starting to get a bit
annoying. So what I ended up doing was creating a Windsor facility that
uses dynamic proxy to automatically implement a settings interface, so I
don't have to update stuff in two places.
For example, say I've got some settings like:
<appSettings>
<add key="Zendesk.Url" value="abc.zendesk.com"/>
<add key="Zendesk.ApiToken" value="aaaaaaaaa"/>
<add key="Git.Email" value="adam-***@public.gmane.org"/>
<add key="Git.Name" value="Adam Connelly"/>
</appSettings>
And a couple of interfaces:
public interface ZendeskConfig
{
string Url { get; }
string ApiToken { get; }
}
public interface GitConfig
{
string Email { get; }
string Name { get; }
}
You can configure your container like this:
var container = new WindsorContainer();
container.AddFacility<AppConfigFacility>();
container.Register(
Component.For<IZendeskConfig>().FromAppConfig(c =>
c.WithPrefix("Zendesk.")),
Component.For<IGitConfig>().FromAppConfig(c => c.WithPrefix("Git."))
);
Then just resolve them / inject them as normal.
It also supports getting the settings from Azure, caching, and computed
properties currently.
The code's available on Github
at https://github.com/adamconnelly/WindsorAppConfigFacility.
What I'm wondering is whether you'd be interested in adding this to
Windsor, and if so, what would I need to change for you to accept it. I'm
more than happy to reformat any files to suit your code format, and make
any changes where I've missed stuff.
Cheers,
Adam
--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-devel+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to castle-project-devel-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/castle-project-devel.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-devel+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to castle-project-devel-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/castle-project-devel.
For more options, visit https://groups.google.com/d/optout.