views:

22

answers:

1

I have a Domain Specific Language, and I would like to register objects that can be instantiated inside.

For instance a class that can do httprequests.

[IoC("HttpRequest", typeof(DslScriptObject), IoCAttribute.IoCLifestyleType.Transient)]
internal class WebRequestDslObj : DslScriptObject
{
    [DslNew]
    public WebRequestDslObj() : this(null, null)
    {}
    [DslNew]
    public WebRequestDslObj([DslParam("uri")]string uristring, [DslOptionalParam("contenttype")] string contenttype) : this(uristring, null)
    {}
}

I then have a class that maps types from my dsl datatypes to c# datatypes (I have them as an IList if that makes any difference), and this works ok, if I do not use Castle to instantiate the object.

But as soon as I want to use IoC to autoregister the various types, then I dont know what to do about the constructors. I have tried to look at setting a CustomComponentActivator, but I got stuck at not being able to find any good example or documentation. Is that a viable path to take? (and will I be able to get around the funny special case for null parameters?)

Anyone have an example of where I can start?

+1  A: 

So what are you trying to do with Windsor, because I'm not sure I see where you're going with it...

If you want to affect how component gets register in Windsor, for example rename parameters, you can write custom ComponentModel construction contributor to do it.

Krzysztof Koźmic
When I encounter a new operator in my dsl, I want to resolve the DslScriptObject with the key that is the class name, and give the parameters. And somewhere in the middle of the resolving, find the right constructor based on the parameters given and instanciate my object.
Cine
So you basically need to map the values from `DslParamAttribute` like "uri" to actual names of .ctor parameters like "uristring", is that correct?
Krzysztof Koźmic
yes, and find the right function (although that part is not really something I need castle to do, except give me all the ConstructorInfo or similar to make the decision)
Cine
In this case I'd use the custom contributor to inspect the DSL element and cache this information, and then use custom selector http://stw.castleproject.org/Windsor.Typed-Factory-Facility-interface-based-factories.ashx#Custom_codeITypedFactoryComponentSelectorcodes_15 to map them so that you'd switch the dependency under key 'uri' to key 'uristring' etc...
Krzysztof Koźmic

related questions