Windsor:How to register components whose component properties must be null on instance resolving.

4 views
Skip to first unread message

ppcanodehuelva

unread,
Oct 15, 2009, 8:26:39 AM10/15/09
to Castle Project Users
Hi everybody,

We are using NH+Castle+uNhaddins. The models are registered on the
container like:

----------------------
IEnumerable<Type> models = typeof
(Product).Assembly.GetTypes()
.Where(t => t.GetInterfaces
().Any(i => i == typeof(IModel)));

foreach (Type impl in models)
container.Register(Component.For
(impl).LifeStyle.Transient);
---------------------

When the container resolves a component which has a reference to
another component, the refenced component is also resolved. I know
that is the default behavior.

With our current nh configuration, it will throw an exception when it
tries to save a component whose dependecy property is not a null
object (object references an unsaved transient instance - save the
transient instance before flushing).

To avoid this situation, after resolving the instance, the instance
properties must be set to null, every time an instance is resolved to
be saved.
---------------------

We would like to configure the container "on a elegant mode" in order
these properties of the resolved instances can be automatically null,
in order not to do the mentioned action.

Any hints about how to achieve it.

Many thanks in advance


Ayende Rahien

unread,
Oct 15, 2009, 8:40:03 AM10/15/09
to castle-pro...@googlegroups.com
Why are you trying to resolve entities from the container?

ppcanodehuelva

unread,
Oct 15, 2009, 9:53:26 AM10/15/09
to Castle Project Users
We are using "uNhaddins" to inject: INotifyPropertyChanged and
IDataError behavior to our entities on a WPF application,which are
resolved through either a SessionFactory which is also configured on
the container or the container when a new instance is created.

Nhibernate.Validation is also configured through the container.

On Oct 15, 2:40 pm, Ayende Rahien <aye...@ayende.com> wrote:
> Why are you trying to resolve entities from the container?
>

Roelof Blom

unread,
Oct 15, 2009, 5:06:57 PM10/15/09
to castle-pro...@googlegroups.com
Hi,

You can disable auto-wiring like this:

container.Register(Component
 .For(impl)
 .LifeStyle.Transient)
 .Activator<MyModelActivator>()

class MyModelActivator: DefaultComponentActivator
{
    protected override void SetUpProperties(object instance, CreationContext context)
    {
        // Do not auto-wire
    }
}

-- Roelof.
Reply all
Reply to author
Forward
0 new messages