Dennis G
Dennis G

Reputation: 21788

Spring.Net get the context Resource from a resource file?

In spring you always use the web.config/app.config for storing your objects like so:

<spring>
    <context>
        <resource uri="config://spring/objects"/>
    </context>
    <objects>
        <description>An  example that demonstrates simple IoC features.</description>
    </objects>
</spring>

or

<resource uri="~/config/objects.xml" />

As sometimes I'm running under some service which doesn't have this web.config I'd like to add my objects to a resource file (*.resx).

How would I do that, so i can get a full IApplicationContext as if I would call IApplicationContext ctx = ContextRegistry.GetContext();?

So basically instead of using the web.config I want to use a resource file to store my objects and initialize my application context with those objects.

Upvotes: 1

Views: 2868

Answers (1)

sbohlen
sbohlen

Reputation: 2019

The mechanics aren't quite the same as defining your objects in a RESX file (which isn't supported at all), but you can easily achieve what's probably your underlying goal: having your config internalized within your assembly rather than externalized into a separate XML file (web.config, app.config, or even just a stand-alone anything.xml file).

You can do this using Spring.NET's assembly:// resource prefix (e.g., assembly://MyAssembly/MyService/objects.xml)/ See http://www.springframework.net/doc-latest/reference/html/objects.html#d4e412 for more details.

Upvotes: 3

Related Questions