Dependency attribute with indication of start container

Jun 11, 2009 at 6:43 AM

What are the options for deciding the container in which the search for a type registration starts when using the dependency attribute ?

Something in the lines of [Dependency("MyStartContainer")]

(I've noticed the possibility to set a registration name)

Should I write my own extension supporting this behaviour or is there another way ?

Jun 12, 2009 at 8:07 AM

I don't understand what behavior you want here, but the Dependency attribute says what, not where. The container that's used to look up the dependency is the one that you called Resolve on, period. There's no global registry of containers or anything like that.

Jun 12, 2009 at 8:15 AM
Edited Jun 12, 2009 at 8:26 AM

Ok, I'll elaborate a bit.

We've coded our own Unity wrapping supporting the usage of a predefined container hiearchy - each container is named and looked up when doing the actual resolving.

Currently we're doing something like this:

public MyClass(...)
{
   this.myThing = TDependencyResolver.Resolve<IMyDependent>("MyContainerName");
}

The "TDependencyResolver" being our wrapping class owning the container hiearchy ("container repository"). We do not support a fluent interface.

What we would like to do is:

public MyClass([Dependency("MyContainerNamer")] myThing)
{
  this.myThing = myThing
}

The same principle applies to setters.

Oct 28, 2009 at 6:46 PM

Sorry, Unity does not (and will not) be doing anything like this, unless it gets voted up as a feature.