Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 5,953 | Comments: 44,399

filter by tags archive

Didja know? Merging Windsor configuration with automatic registration


One of the most annoying things that we have to do during development is updating configuration files. That is why convention over configuration is such a successful concept. The problem is what to do when you can mostly use the convention, but need to supply configuration values as well.

Well, one of the nice things about Windsor is the ability to merge several sources of information transparently. Given this configuration:

<configuration>
	<configSections>
		<section name="castle"
			type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
	</configSections>
	<castle>
		<facilities>
			<facility id="rhino.esb" >
				<bus threadCount="1"
						 numberOfRetries="5"
						 endpoint="msmq://localhost/demo.backend"
             />
				<messages>
				</messages>
			</facility>
		</facilities>
		<components>
			<component id="Demo.Backend.SendEmailConsumer">
				<parameters>
					<host>smtp.gmail.com</host>
					<port>587</port>
					<password>*****</password>
					<username>*****@ayende.com</username>
					<enableSsl>true</enableSsl>
					<from>*****@ayende.com</from>
					<fromDisplayName>Something</fromDisplayName>
				</parameters>
			</component>
		</components>
	</castle>
</configuration>

And this auto registration:

var container = new WindsorContainer(new XmlInterpreter());
container.Register(
	AllTypes.Of(typeof (ConsumerOf<>))
		.FromAssembly(typeof(Program).Assembly)
	);

We now get the benefit of both convention and configuration. We can let the convention pick up anything that we need, and configure just the values that we really have to configure.


Comments

Bill Pierce

How did we ever code before Windsor?

configurator

Excuse my ignorance; what does castle Windsor do?

configurator

Heh, I guess I had that coming...

Steve

Thanks Ayende, I like this flexibility as well - glad to see you point this out.

Speaking of:

container.Register(

AllTypes.Of(typeof (ConsumerOf<>))

    .FromAssembly(typeof(Program).Assembly)

);

Is that possible to do in xml right now ?

The features of adding all types of an assembly is one of my favorites, and why I end up doing it in code. So I've been curious if that is a part of the xml capability?

So far, I love how this works with asp.net mvc

Using MvcContrib I register all my controllers, then all the services that the controllers use (using your syntax above), then all the DAO's that the services use.

It's a thing of beauty :)

I blog about how to do the event wiring programmatically as well:

http://blogger.forgottenskies.com/?p=295

Again, thanks for pointing out how to combine the two together!

Happy New Year!

Ayende Rahien

Steve,

No, you can't do that from XML by default.

It should be pretty easy to write a facility to do this, however.

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. Comparing developers - 38 minutes from now

There are posts all the way to Jun 30, 2015

RECENT SERIES

  1. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
  2. Special Offer (2):
    27 May 2015 - 29% discount for all our products
  3. RavenDB Sharding (3):
    22 May 2015 - Adding a new shard to an existing cluster, splitting the shard
  4. Challenge (45):
    28 Apr 2015 - What is the meaning of this change?
  5. Interview question (2):
    30 Mar 2015 - fix the index
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats