Hi,
I have been using dependency injection described by Orand under http://orand.blogspot.com/2006/10/wc...injection.html.
Now I'd like to integrate logging via AOP into my service class. Therefore I think it's necessary to "wrap" my service object as Target of a ProxyFactoryObject. But how do I have to "connect" it with the requirements of the WCF (definition of endpoints etc.)?
Currently my implementation looks like this:
1. App.config:
<spring>
..
<objects xmlns="http://www.springframework.net">
<object id="loggingAroundAdvice" type="MyProject.Spring.LoggingAroundAdvice, MyProject">
<property name="Logger" value="MyService" />
</object>
<object id="myService" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target"><object type="MyProject.MyService, MyProject"/></property>
<property name="InterceptorNames">
<list><value>loggingAroundAdvice</value></list>
</property>
</object>
</objects>
</spring>
..
<system.serviceModel>
<services>
<service name="MyProject.MyService">
<endpoint address="MyServiceBasic" binding="basicHttpBinding" contract="MyProject.IMyService" />
</service>
</services>
</system.serviceModel>
2. Providing ProxyFactoryObject for my service (SpringInstanceProvider):
public class SpringInstanceProvider : IInstanceProvider
{
private Type _serviceType;
public SpringInstanceProvider(Type serviceType)
{
_serviceType = serviceType;
}
public object GetInstance(InstanceContext instanceContext, Message message)
{
object result = null;
IApplicationContext context = ContextRegistry.GetContext();
string[] objectNames = context.GetObjectNamesForType(typeof(ProxyFactoryO bject), true, true);
foreach (string name in objectNames)
{
ProxyFactoryObject factory = (ProxyFactoryObject)context.GetObject(name);
if (factory.TargetSource.TargetType.Equals(_serviceTy pe))
{
if (result == null)
{
result = factory.GetObject();
break;
}
}
}
return result;
}
}
3. Creation of ServiceHost:
IMyService myService = (IMyService)new SpringInstanceProvider(typeof(MyService)).GetInsta nce(null);
using (ServiceHost host = new ServiceHost(myService, baseAdresses))
{
host.Open();
..
}
By this way no endpoints can be found by the host because the service object is not of the desired type but a proxy object ..
Thanks for any hint!


Reply With Quote

