I found a good post: Singleton WCF Proxy .
It's about implementing the WCF proxy life cycle using the Castle Windsor container .
Performing an abstract class AbstractLifestyleManagerfrom Castle.MicroKernel.Lifestylethe namespace override 3 methods: Resolve, Disposeand Release. In the method, Releasewe have access to the context from which we can resolve the service instance.
I copied the code from this post (with a slight change) below:
public class SingletonWCFProxyLifestyleManager : AbstractLifestyleManager
{
private object instance;
public override object Resolve(Castle.MicroKernel.CreationContext context)
{
lock (base.ComponentActivator)
{
if (this.instance == null)
{
this.instance = base.Resolve(context);
}
else
{
ICommunicationObject communicationObject = this.instance as ICommunicationObject;
if (communicationObject != null &&
communicationObject.State == CommunicationState.Faulted)
{
try
{
communicationObject.Abort();
}
catch { }
this.instance = base.Resolve(context);
}
}
}
return this.instance;
}
public override void Dispose()
{
if (this.instance != null)
{
base.Release(this.instance);
}
}
public override void Release(object instance)
{
}
}
, Unity. , LifetimeManager Microsoft.Practices.Unity ( IRequiresRecovery).
, , :
public class SingletonWCFProxyLifestyleManager : LifetimeManager, IRequiresRecovery
{
public override object GetValue()
{
throw new NotImplementedException();
}
public override void RemoveValue()
{
throw new NotImplementedException();
}
public override void SetValue(object newValue)
{
throw new NotImplementedException();
}
#region IRequiresRecovery Members
public void Recover()
{
throw new NotImplementedException();
}
#endregion
}
:
ββ ( Unity), ( Castle Windsor)?
(PS: , ?).