How to register resources at run time?

24 views
Skip to first unread message

Alec

unread,
Dec 4, 2011, 8:21:03 PM12/4/11
to OpenRasta
Hi all
At application start time I need to load an assembly containing
resource and handler definitions and dynamically register them into
the ResourceSpace , that means to NOT have this registration process
hardcoded as is shown below.:
ResourceSpace.Has.ResourcesOfType<Home>()
.AtUri("./home")
.HandledBy<HomeHandler>().AsXmlDataContract().And.AsJsonDataContract();

how can I do that?

Sebastien Lambla

unread,
Dec 5, 2011, 8:05:51 PM12/5/11
to open...@googlegroups.com
I don't understand your question.

If you're asking if you can register new resources at any random time, the answer is no, as a lot of the processing pipeline depends on knowing everything about the application when the application starts. If you're asking if you can register handlers and resources from random assemblies that you'd load the first time around, yes you can do that. You can either scan the assemblies yourself and register them using the weakly-typed fluent api, or provide your own extension method on top of the metamodel repository.

Alec

unread,
Dec 7, 2011, 9:33:40 PM12/7/11
to OpenRasta
Hi Sebastien
What I want to do is the second option " register handle rs and

resources from random assemblies that you'd load the first time
around",
I know how to scan the assemblies and get the resource types and
handlers to be registered (through reflection) , but as I'm new using
Open Rasta I don't know what exactly what do you mean with register
them using the weakly-typed fluent api, or provide an extension method
on top of the metamodel repository, are there some examples or docs I
can see, or you can point me to the classes I need to inspect.
Besides that is there some method to override or event to subscribe
to catch the application start up so I can put the code scanning the
assemblies and publishing the resources there?
Thanks a lot for your answer Sebastien

Sebastien Lambla

unread,
Dec 8, 2011, 4:02:19 AM12/8/11
to open...@googlegroups.com
Type resourceType = ...
Type handlerType = ...

ResourceSpace.Has.ResourcesOfType(resourceType)...HandledBy(handlerType)

You can do that recursively.

Otehrwise, you can extend the fluent API with your own registration and add a ResourceDefinition message yourself. There's no actual documented exampes on that. Basically, you write an extension method on IHas or IUses, you cast to IFluentTarget, this gives you the repository of configuration. You can then add a ResourceDefinition which contains the resource type and associated uris / handlers.


________________________________________
From: open...@googlegroups.com [open...@googlegroups.com] on behalf of Alec [alec...@gmail.com]
Sent: 08 December 2011 02:33
To: OpenRasta
Subject: [openrasta] Re: How to register resources at run time?

Reply all
Reply to author
Forward
0 new messages