Singelton for Property Injection

Mar 3, 2008 at 3:52 AM
This is probably a simple question, but I am just getting started with Unity and would really appreciate a point in the right direction.

How do I specify that a property (marked with the <Dependency> attribute) should be created as a singleton?

Mar 3, 2008 at 5:25 AM
You don't specify it on the property, you specify it on the type when you configure the container.

If you have:

class Foo {{
public Bar MyBar {{ get {{ ... }} set ... }}}}}

Then when you configure the container, you tell it that you want Bar's to be singletons:


Then from that point on every time the container resolves a Bar instance, it'll return the same one.

Hope this helps,