Hey,
Well, the point is that I want to use constructor dependency injection (the
IFileAdapter is configured by the tx-facility); I’d like to use DI and still
be able to wrap lots of interceptors around the targets in order to do
full-fledged AOP :)…
I tried this:
(k => {
Console.WriteLine("Generating");
var tmp = _Generator.CreateClassProxy(
typeof (TSettings), options, new object[] {c.Resolve<IFileAdapte
r>()},
new AutoSave(),
new GetProperties()) as TSettings;
Console.WriteLine(string.Format("Done with gen, type {0}, c'tors: {1}, dep:
{2}", tmp.GetType(),
string.Join(",", tmp.GetType().GetConstructors().Select(ctor => ctor.ToStrin
g()).ToArray()), tmp.Fa));
return tmp;
}
Which gives output:
Generating
[my interceptor output from c'tor calls to properties]
Methods inspected
Intercepted Castle.Proxies.Invocations.PropertiesSettings_set_First
Intercepted Castle.Proxies.Invocations.PropertiesSettings_set_Grades
Intercepted Castle.Proxies.Invocations.PropertiesSettings_set_Items
Intercepted Castle.Proxies.Invocations.PropertiesSettings_set_Grades
Done with gen, type Castle.Proxies.PropertiesSettingsProxy, c'tors: Void
.ctor(Castle.Core.Interceptor.IInterceptor[],
Castle.Services.Transaction.IO.IFileAdapter), dep:
Castle.Services.Transaction.IO.FileAdapter
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)
HOWEVER:
========
Registering the interceptors as well and not using the proxy generator works
fine. Then the question is merely how to specify a generation hook for it?
Or alternatively how to mimic the default behavior...
Cheers,
Henrik
From: [email protected]
[mailto:[email protected]] On Behalf Of John Simons
Sent: den 27 augusti 2010 00:14
To: [email protected]
Subject: Re: Generate proxy for transactions and also through e.g. factory
method?
I'm sure it can't be this easy, but have you tried to do what the exception
tells you?
Add a default public constructor to PropertiesSettings class.
Cheers
John
________________________________________
From: Henrik Feldt <[email protected]>
To: [email protected]
Sent: Fri, 27 August, 2010 6:48:49 AM
Subject: Generate proxy for transactions and also through e.g. factory
method?
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.
--
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.
--
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.