Hi,
I'm trying to extend a transactional class to create a nifty
properties-class that auto-saves, keeps key-values updated and is
transactional. My final aim being to create a bunch of test-cases for
transaction failure handling and retry-policies.
I got code like this:
private static readonly ProxyGenerator _Generator = new ProxyGenerator();
public static IWindsorContainer CreateContainer<TSettings>() where TSettings
: SettingsBase
{
var c = new WindsorContainer();
c.AddFacility<FactorySupportFacility>();
c.AddFacility<TransactionFacility>();
var options = new ProxyGenerationOptions(new
SettingsProxyGenerationHook());
c.Register(
Component.For<ITransactionManager>().ImplementedBy<DefaultTransactionManager
>(),
Component.For<TSettings>()
.UsingFactoryMethod(k =>
_Generator.CreateClassProxy(
typeof(TSettings), options, new
object[] { c.Resolve<IFileAdapter>() },
new AutoSave(),
new GetProperties()) as TSettings)
.LifeStyle.Transient
);
return c;
}
public static TSettings CreateSettings<TSettings>() where TSettings :
SettingsBase
{
var s = CreateContainer<TSettings>().Resolve<TSettings>();
return s;
}
[Test]
public void CreatingSettings()
{
CreateSettings<PropertiesSettings>();
}
Which yields this exception:
Test 'ProxyTests.CreatingSettings' failed:
Castle.MicroKernel.ComponentActivator.ComponentActivatorException :
FactoryActivator: could not proxy Castle.Proxies.PropertiesSettingsProxy
----> System.ArgumentException : Can not instantiate proxy of class:
PropertiesSettings.
Could not find a parameterless constructor.
Parameter name: constructorArguments
at Castle.Facilities.FactorySupport.FactoryActivator.Create(Object
factoryInstance, String factoryId, MethodInfo instanceCreateMethod, String
factoryCreate, CreationContext context)
at
Castle.Facilities.FactorySupport.FactoryActivator.Instantiate(CreationContex
t context)
at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCrea
te(CreationContext context)
at
Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(Crea
tionContext context)
at
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContex
t context)
at
Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext
context, Boolean track)
at
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler
handler, Type service, IDictionary additionalArguments)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler
handler, Type service)
at Castle.MicroKernel.DefaultKernel.get_Item(Type service)
at Castle.Windsor.WindsorContainer.Resolve(Type service)
at Castle.Windsor.WindsorContainer.Resolve[T]()
SettingsBaseTests.cs(52,0): at
ProxyTests.CreateSettings[TSettings]()
SettingsBaseTests.cs(59,0): at ProxyTests.CreatingSettings()
What is the best way to go about fixing this? Is there a way to specify a
generation hook through the fluent registration api, so that I don't have to
use a factory method? What am I missing?
SettingsBase, that abstract base class for PropertiesSettings (I had a
bright moment naming that one!), has the TransactionalAttribute attached.
Cheers
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" 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/castle-project-users?hl=en.