last day (15 days later) » 

5:08 PM
0
Q: Unity Interface Interception across multiple layers

zeencatAny advice would be greatly appreciated on this. I have a standard NTier application which implements Unity DI. This works absolutely fine, the unity container is created and registers everything within the BAL. I've also got interface interception configured using attribute decoration above m...

 
When you say NTier do you mean that each tier is running in a different process? If so the container will need to be configured in each one.
 
By NTier I mean, BAL, and DAL as well as some other projects which sit in parallel. I'm using constructor injection within each of the layers as well. This seems to work fine which is why I'm a little at a lose as to why the interface interception isn't working in any layer other than the BAL.
 
Did you configure interception for other interfaces as well? By the pasted code only appears that is for the BAL one
 
The BAL has a reference to a project called DistributionProviders. The BAL layer registers the the ISftpState interface to the unity container, the ISftpState interface belongs to the DistributionProviders project. The DI works absolutely fine, its just the interface intersception that doesnt work on the ISftpState. However if I register an interface that belongs to the BAL layer to use interface intersception it works fine.
 
I think I am going to need more of your code here... is the container the same in both layers?
 
5:08 PM
I've added a little more code. Not sure what else to show. There is only one container which registers everything for all the layers.
 
Going to have a look
so basically you have classes implementing the same interface in both layers. But the only that seems to be registered in unity is the implementation on the BAL, am I right?
 
No, I dont have classes implementing the same interface is both layers.
 
So you are calling the BAL from teh DistributionProviders and that is when it doesn't work?
 
The BAL has an interface for example called IControl, which is implemented within a class called Control. Both reside in the BAL layer. This type is then registered within the container. _container.Register<IControl, Control>(). So within the concrete implementation of Control in the constructor I have public Control(ISftpstate sftpstate)
ISftp state is defined within the DistributionProvider layer. The BAL only holds a reference to the DP layer.
 
That sounds right
It should work!
:(
 
5:16 PM
It doesnt, this is why I'm really confussed. Factorily speaking my project is designed correctly. :(
 
Can you check when you debug that the sftpstate object in Control is a proxy generated by unity? Just to be sure
 
Say the control has a method called Execute and I decorate it with the attribute [ProcessLogging] and I register the IControl to have interface intersception. This works fine but when I register the ISftstate to have it and then decorate one of the methods within it it doesnt work.
Stupid question but how do I check?
 
in the debugger put a break point on the Control constructor. And just mouse over the parameter and see which type is it.
 
The ISFTpState is assigned properly within the Control class when the Control is resolved.
 
if it is SFtpState type then its wrong. It must be something like Unity.Proxy.whatever
Unity creates a proxy object that implements your interface and wraps the actual implementation. SO it can plug all the interception on it
 
5:26 PM
They dont appear to be proxies, they appear to be concretes.
 
Right... can I see your _container configuration if not fully at least enough of it?
 
sure
private static volatile UnityDiContainer _instance;
private static readonly object LockObject = new object();
private IUnityContainer _container;

public IUnityContainer Container
{
get { return _container; }
}

public static UnityDiContainer Instance
{
get
{
lock (LockObject)
{
return _instance ?? (_instance = new UnityDiContainer());
}
}
}

private void CreateContainer()
{
_container = parentContainer;
_container.RegisterType<IControl, Control>();

if (Convert.ToBoolean(new AppConfigSectionReader().ReadConfigSection("EnableProcessLogging"))) ;
there should be another registertype on the container of <Isftpstate,sftpstate>
its a very cut down version but this gives the idea of what I've got
I can upload a very small project I've created to test this, it gives the same problem. I'm obviously doing something wrong.
 
Well that seems to be right
that would be great
not sure if I would be able to look at it today (about to leave the office!) but probably I can have a look this weekend, or someone else can look at it before
I never used attribute interceptors in Unity, I have always registered them explicitly
 

last day (15 days later) »