4

I am wiring up my first SubSonic 3 application (in an ASP.NET MVC 1.0 front-end) and am looking at Rob's SimpleRepository. I'm using Castle.Windsor as an injection framework.

In my application startup, I configure Castle to bind a SubSonic SimpleRepository to a SubSonic IRepository. Nothing complicated there. However, the SimpleRepository has a ctor overload which takes two values: a connection string name and a set of SimpleRepositoryOptions. Not having dug too deep into Castle in the past, it's not clear if there is a way to specify the ctor arguments via configuration (or some other means).

Right now, I have a custom implementation of the SimpleRepository that explicitly creates a SimpleRepository with those arguments in it's parameterless ctor, but if I want to change these at any point in time, it requires changing the code and recompiling.

Is there a more elegant way to configure Castle to take constructor arguments?

mskfisher
  • 3,291
  • 4
  • 35
  • 48
nkirkes
  • 2,635
  • 2
  • 21
  • 36

2 Answers2

5

If you're configuring Windsor using an XML file, you define your ctor arguments and their values like this:

<component id="repository" service="IRepository" type="SimpleRepository" ...>
    &ltparameters>
        <connectionString>your connection string</connectionString>
        ...
    &lt/parameters>
</component>

See the Windsor configuration reference for more info:

http://www.castleproject.org/container/documentation/v1rc3/manual/windsorconfigref.html

Ty.
  • 2,220
  • 1
  • 15
  • 14
4

See this wiki page. What's called "parameters" on that page is either a constructor parameter (which is a required parameter) or a property (optional parameter)

Simon Hughes
  • 3,534
  • 3
  • 24
  • 45
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275