I am currently trying to use the registration by convention with interface interception. Unfortunately, it seems that I am doing something wrong because I am running in a StackOverflowException
in the Unity.Container.dll
on the first resolve...
This is what I tried:
container = new UnityContainer();
container.RegisterTypes(AllClasses.FromAssemblies(Assembly.GetAssembly(typeof(IFoo)),
WithMappings.FromMatchingInterface,
getInjectionMembers: c => new InjectionMember[] { new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<IBarBehavior>()});
It seems that now all classes are registered, instead of only classes with matching interfaces (Foo --> IFoo
). Without the interface interception, the statement is fine and my classes are registered as expected.
Any idea or help would be great!
Update:
I have found this post in a different question that states when a LifeTimeManager
or interception
behavior is used all types are registered. By using these information, the following code produced the expected outcome:
container.RegisterTypes(AllClasses.FromAssemblies(Assembly.GetAssembly(typeof(IFoo)).
Where(t => t.GetTypeInfo().GetInterface("I" + t.Name) != null),
WithMappings.FromMatchingInterface,
getInjectionMembers: c => new InjectionMember[] { new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<IBarBehavior>()});