PDA

View Full Version : objects name conflicts with several contexts (1 per assembly)


Gengis
02-20-2007, 04:55 PM
Hello,

I have 5 projets and a context for each of them.
I use all of these projects in a "asp.net web application", I load the context as follow (in the web.config)

<spring>
<context>
<resource uri="assembly://[assembly1]/[Path]/context.xml"/>
<resource uri="assembly://[assembly2]/[Path]/context.xml"/>
<resource uri="assembly://[assembly3]/[Path]/context.xml"/>
<resource uri="assembly://[assembly4]/[Path]/context.xml"/>
<resource uri="assembly://[assembly5]/[Path]/context.xml"/>
</context>
</spring>

But I have a name conflicts because of two objects with the same id (one in the context.xml of assembly1, one in the context.xml of assembly2). Each context is 100% autonomous and does not depend on others. When I only load a single assembly (=> 1 context) everything works fine.

Name conflict results with "invalid type" injection.

How can I solve such conflicts ? Is it possible to declare dependencies with a 'lookup scope', which meaning would be "look for dependencies in". So I can tell to spring "resolve dependencies by only looking in the assembly".

Thanks,

PS : I load the context as follow : ContextRegistry.GetContext()

Bruno Baia
02-20-2007, 11:37 PM
Salut Gengis,

You are using different resources here, but you still have only 1 context, the root context.
If you are not using the WebContextHandler, you can define multiple contexts :

<context>
<context name="context1">
<resource uri="assembly://[assembly1]/[Path]/context.xml"/>
</context>
<context name="context2">
<resource uri="assembly://[assembly2]/[Path]/context.xml"/>
</context>
[...]
</context>

And using them independently :

ContextRegistry.GetContext("context1");
ContextRegistry.GetContext("context2");


See reference documentation :
4.13.1. Context Hierarchies (http://www.springframework.net/doc-latest/reference/html/objects.html#context-functionality-hierarchy)


Hope this helps,
Bruno

Ralph_Lange
03-06-2007, 09:18 AM
What do the expressions [assembly1] and [Path] mean? With which value do I have to set them?

Greetings Ralph Lange:)

Bruno Baia
03-06-2007, 10:50 AM
Hi,

see reference documentation about this :
Built-in IResource implementations (http://www.springframework.net/doc-latest/reference/html/resources.html#d0e4666)


Bruno