App Config Facility

20 views
Skip to first unread message

adam.rp...@gmail.com

unread,
Oct 9, 2014, 8:58:50 AM10/9/14
to castle-pro...@googlegroups.com
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="ad...@email.com"/>
    <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.


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

hammett

unread,
Oct 9, 2014, 5:23:48 PM10/9/14
to castle-pro...@googlegroups.com
Looks pretty cool. Good job.

Regarding adding it to windsor, I'd prefer to list it on our website
(maybe with some nuget id reference?) so we give it visibility but
without the implied maintenance obligation.
> --
> 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-d...@googlegroups.com.
> To post to this group, send email to castle-pro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/castle-project-devel.
> For more options, visit https://groups.google.com/d/optout.



--
Cheers,
hammett
http://www.d-collab.com/
http://www.hammettblog.com/

Krzysztof Koźmic

unread,
Oct 9, 2014, 5:38:23 PM10/9/14
to castle-pro...@googlegroups.com

+1

adam.rp...@gmail.com

unread,
Oct 10, 2014, 8:28:18 AM10/10/14
to castle-pro...@googlegroups.com
That's fine by me. In that case I'll look into putting it up on nuget / symbol source, and add decent documentation to the github page.

adam.rp...@gmail.com

unread,
Oct 17, 2014, 8:29:08 AM10/17/14
to castle-pro...@googlegroups.com
Hi,

Just to say I've got round to creating a NuGet package, and adding documentation about how to use the facility to the GitHub page.

All the info about it should be in the readme at https://github.com/adamconnelly/WindsorAppConfigFacility.

If you fancy adding this to the site, that would be really cool.

Cheers,
Adam

Jonathon Rossi

unread,
Oct 17, 2014, 8:39:40 AM10/17/14
to Castle Project Development
Our wiki and web site are both editable (with moderation) by users. The wiki is probably the best place to mention it.

--
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-d...@googlegroups.com.
To post to this group, send email to castle-pro...@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-devel.
For more options, visit https://groups.google.com/d/optout.



--
Jono

Adam Connelly

unread,
Oct 20, 2014, 8:46:45 AM10/20/14
to castle-pro...@googlegroups.com
Cheers - have added it to the wiki now.

--
You received this message because you are subscribed to a topic in the Google Groups "Castle Project Development List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/castle-project-devel/5l4bNqUVmls/unsubscribe.
To unsubscribe from this group and all its topics, send an email to castle-project-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages