LinFu and Spring specific DynProxyTypeValidator subclass.

77 views
Skip to first unread message

Nik Govorov

unread,
Nov 22, 2009, 1:27:43 PM11/22/09
to nhusers
Hi.
I think that ProxyFactoryFactory(from NHibernate.ByteCode.LinFu and
NHibernate.ByteCode.Spring) should returns thier own implementations
of IProxyValidator without checking default constructor:

using CommonDynProxyTypeValidator =
NHibernate.Proxy.DynProxyTypeValidator;

namespace NHibernate.ByteCode.Castle
{
public class DynProxyTypeValidator : CommonDynProxyTypeValidator
{
protected override void CheckHasVisibleDefaultConstructor
(System.Type type)
{

}
}
}
Now, for using entities without default ctor(apart from implementing
BytecodeProvider), I have to disable proxy validation
(use_proxy_validator), but there are some other important checks in
DynProxyTypeValidator(also it's possible to create own
ProxyFactoryFactory basen on LinFu or Spring factory, but I dont like
this way).
Thanks.

Fabio Maulo

unread,
Nov 23, 2009, 7:36:30 AM11/23/09
to nhu...@googlegroups.com
If you don't like the ProxyValidator you can:
1) disable it <property name="use_proxy_validator">false</property>
2) override the bytecode provider
<property name="proxyfactory.factory_class">YourOwn.ByteCode.XYZ.ProxyFactoryFactory, YourOwn.ByteCode.XYZ</property>
and provide your own validation.

In order to use entities without default parameterless ctor:

Part of that code now is available directly in Spring.NET+NH integration.

2009/11/22 Nik Govorov <nikita....@gmail.com>

--

You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=.





--
Fabio Maulo

Nik Govorov

unread,
Nov 23, 2009, 2:39:33 PM11/23/09
to nhusers
Fabio, this is clear, but creating own factory is overhead(if I dont
want use any IOC).
In my ByteCodeProvider(exactly in
ReflectionOptimizer.CreateCreateInstanceMethod) I want to use:
return () => FormatterServices.GetUninitializedObject(type);
instead of :
ThrowExceptionForNoDefaultCtor(type);
and that works fine with linfu and spring proxies(but their factories
should have validator without checking default ctor).
Or I have something wrong?
Thank for reply.

On 23 ноя, 15:36, Fabio Maulo <fabioma...@gmail.com> wrote:
> If you don't like the ProxyValidator you can:
> 1) disable it <property name="use_proxy_validator">false</property>
> 2) override the bytecode provider
> <property
> name="proxyfactory.factory_class">YourOwn.ByteCode.XYZ.ProxyFactoryFactory,
> YourOwn.ByteCode.XYZ</property>
> and provide your own validation.
>
> In order to use entities without default parameterless ctor:http://fabiomaulo.blogspot.com/2008/11/entities-behavior-injection.html
>
> Part of that code now is available directly in Spring.NET+NH integration.
>
> 2009/11/22 Nik Govorov <nikita.govo...@gmail.com>
>
>
>
>
>
> > Hi.
> > I think that ProxyFactoryFactory(from NHibernate.ByteCode.LinFu and
> > NHibernate.ByteCode.Spring) should returns thier own implementations
> > of IProxyValidator without checking default constructor:
>
> > using CommonDynProxyTypeValidator =
> > NHibernate.Proxy.DynProxyTypeValidator;
>
> > namespace NHibernate.ByteCode.Castle
> > {
> >    public class DynProxyTypeValidator : CommonDynProxyTypeValidator
> >    {
> >        protected override void CheckHasVisibleDefaultConstructor
> > (System.Type type)
> >        {
>
> >        }
> >    }
> > }
> > Now, for  using entities without default ctor(apart from implementing
> > BytecodeProvider), I have to disable proxy validation
> > (use_proxy_validator), but there are some other  important checks in
> > DynProxyTypeValidator(also it's possible to create own
> > ProxyFactoryFactory basen on LinFu or Spring factory, but I dont like
> > this way).
> > Thanks.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com >
> > .

Fabio Maulo

unread,
Nov 23, 2009, 3:46:02 PM11/23/09
to nhu...@googlegroups.com
Probably the bytecode implemented inside the Framework Spring.NET has a different ProxyValidator.
In NH, by default, all bytecode implementations are sharing the same DefaultProxyValidator using the NH default behaviour where the parameterless ctor is required.

If you don't want the default behaviour you can inject your own.
If you don't want work with an IoC you don't need to touch the bytecode provider for Proxy stuff and you can use a custom Tuplizer.

Now... if you have an Entity with a NO default parameterless ctor and you don't want use an IoC nor a Tuplizer you should explain me how NH should understand how use your ctor with parameter and how we can create a Proxy of your class.
Can you send an example ?

2009/11/23 Nik Govorov <nikita....@gmail.com>
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=.





--
Fabio Maulo

Fabio Maulo

unread,
Nov 23, 2009, 3:48:01 PM11/23/09
to nhu...@googlegroups.com
1) disable it <property name="use_proxy_validator">false</property>


2009/11/23 Nik Govorov <nikita....@gmail.com>
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=.





--
Fabio Maulo

Nik Govorov

unread,
Nov 24, 2009, 8:34:57 AM11/24/09
to nhusers
> you should explain me how NH should understand how use your ctor with parameter and how we can create a Proxy of your class.
If there is no default ctor and we do not need use IOC, as the last
(slow) alternative we can use FormatterServices.GetUninitializedObject
(type).

>Can you send an example

Sample:

public class Entity
{
private Guid key;
private string name;

public Entity(Guid key, string name)
{
this.key = key;
this.name = name;
}

public virtual Guid Key
{
get { return key; }
protected set { key = value; }
}

public virtual string Name
{
get { return name; }
protected set { name = value; }
}
}

>disable it <property name="use_proxy_validator">false</property>
This will cause to "delayed" runtime errors for lazy-entities with non-
virtual(non-interface) members.

>Probably the bytecode implemented inside the Framework Spring.NET has a different ProxyValidator.
No, they use NHibernate.Proxy.DynProxyTypeValidator.

On 23 ноя, 23:48, Fabio Maulo <fabioma...@gmail.com> wrote:
> 1) disable it <property name="use_proxy_validator">false</property>
>
> 2009/11/23 Nik Govorov <nikita.govo...@gmail.com>
> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Bunsubscribe@googlegroup s.com>>
Reply all
Reply to author
Forward
0 new messages