Crap, you're right. I can't believe I left the non-generic overloads off the PolicyInjection class.
Ok, so it's still possible to port, it'll just take a few more changes is all. The best bet is to go throught the Unity container instead. The PolicyInjection facade is now just a wrapper around an appropriately configured container anyway.
So, remove the factory and PolicyInjector from your member variables, and add this instead:
private static readonly IUnityContainer container;
Add a static constructor to initialize the container:
static PolicyInjectionInstanceProvider()
{
// Create container
container = new UnityContainer()
.AddNewExtension<Interception>();
// Read PIAB config and apply it to the container
IConfigurationSource configSource = ConfigurationSourceFactory.Create();
PolicyInjectionSettings settings = (PolicyInjectionSettings)configSource.GetSection(PolicyInjectionSettings.SectionName);
if(settings != null)
{
settings.ConfigureContainer(container, configSource);
}
}
And then change GetInstance to this:
public object GetInstance(System.ServiceModel.InstanceContext instanceContext, System.ServiceModel.Channels.Message message)
{
Type type = instanceContext.Host.Description.ServiceType;
if (serviceContractType != null)
{
lock(_sync)
{
container.Configure<Injection>()
.ConfigureInterceptorFor(serviceContractType, new TransparentProxyInterceptor());
container.RegisterType(serviceContractType, type);
return container.Resolve(serviceContractType);
}
}
else
{
if (!type.IsMarshalByRef)
{
throw new ArgumentException("Type Must inherit MarshalByRefObject if no ServiceInterface is Specified");
}
lock(_sync)
{
container.Configure<Injection>()
.ConfigureInterceptorFor(type, new TransparentProxyInterceptor());
return container.Resolve(type);
}
}
}
That should do it. This also has the advantage of setting you up to use the container for other stuff too. All you'd need to do is add a step to configure the container as well in that static constructor. In fact, I'd recommend you do that - that way you can avoid the repeated configuration of the Interceptor and the type mappings; just do them once in config.
Hope this helps,
-Chris