On second thought, and this may be more useful, why is
if (ReflectHelper.IsAbstractClass(mappedClass))
{
throw new InstantiationException("Cannot
instantiate abstract
class or interface: ", mappedClass);
}
first? Shouldn't this only be before
else
{
try
{
return
constructor.Invoke(null);
}
catch (Exception e)
{
throw new
InstantiationException("Could not instantiate entity:
", e, mappedClass);
}
}
as the optimizer or bytecode provider may know how to create an
instance of a specific interface. It seems to be that NHibernate
should only fall back to using the default constructor (and hence have
to check if it is an abstract class or interface) if and only if the
optimzer/bytecode provider failed to instantiate a new instance of a
specific class.
On Mar 9, 5:55 pm, Fabio Maulo <[email protected]> wrote:
> which is the test ?
>
> 2010/3/9 TU <[email protected]>
>
>
>
> > The below function throws an exception (in my case when it tries to
> > instantiate a component interface), if the mappedClass is an
> > interface, shouldn't it goto the second/third elseif part and use
> > either the optomized creator or the bytecode provider to look up the
> > type? (This way you could have the interface type in your IoC/DI
> > setup and it would create it etc). Or am i just misunderstanding
> > something? This works for everything else (i have interfaces
> > everywhere instead of concrete classes and use DI to set them up for
> > nhibernate) but for my component i get this exception. Is this a bug
> > or to be expected? Also if it is to be expected, why? Can this be
> > fixed? (Reorder the if so that if it dosn't find it in the IoC then it
> > throws the exception maybe?) If not is there a work around or am i
> > doing things totally wrong? Thank you!
> > public object Instantiate()
> > {
> > if (ReflectHelper.IsAbstractClass(mappedClass))
> > {
> > throw new InstantiationException("Cannot
> > instantiate abstract
> > class or interface: ", mappedClass);
> > }
> > else if (optimizer != null)
> > {
> > return optimizer.CreateInstance();
> > }
> > else if (mappedClass.IsValueType)
> > {
> > return
> > Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(mappedClass,
> > true);
> > }
> > else if (constructor == null)
> > {
> > throw new InstantiationException("No default
> > constructor for
> > entity: ", mappedClass);
> > }
> > else
> > {
> > try
> > {
> > return constructor.Invoke(null);
> > }
> > catch (Exception e)
> > {
> > throw new
> > InstantiationException("Could not instantiate entity:
> > ", e, mappedClass);
> > }
> > }
> > }
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> Fabio Maulo
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.