This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
Added support to keep and resolve aspects from IoC container #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
Recently I've learned about SNAP. Tried to use it in a project, I'm currently working on. And I ran into lack of the ability to keep aspects in container and having SNAP to resolve aspect instances from the container just before interception occurs.
Problems of direct aspect instantiation
Here are some problems I see with current approach of direct aspect instantiation.
LoggerAspect
class which have dependency toDiagnosticService
, which is already managed by container. Currently there is no way to supply external dependency into an aspect class. This downgrades aspect classes to be very simple ones (w/o external dependencies), or forces the developer to get access to external dependencies via static ServiceLocator.It would be nice to allow container manage both aspects and business components and resolve dependencies between them rather than forcing developer in burden of doing it on its own. So, I've decided to add this valuable feature to SNAP.
New behavior
All changes are non-breaking!
This behavior is applied for all of 5 currently supported containers: Autofac, Castle.Windsor, Ninject, StructureMap, LinFu.
Detailed commit list
8f62fbf
Refactor
MethodInterceptor
class.Do some refactoring of
MethodInterceptor
class. ExtractSignatureCache
and related functionality to separate class (Interception). Interception notion is a binding of the interceptor type being applied to the specific method, which is decorated with the specific attribute. This class allow to get target attribute and method info for given method invocation (intercepted one).c785ae6
Add concept
InterceptorRegistration
.We need to avoid creating aspect instances of SNAP configuration step.
Do not create instances of
IAttributeInterceptor
directy on aspect configuration build step. Just create list of interceptor registrations (that is, settings of InterceptorType, TargetAttribute and Order). Defer instantiation ofIAttributeInterceptor
, move this logic it inMasterProxy
class just before invoking the interceptor.e367e47
Added support for
Snap.Autofac
to keep and resolve aspects from container instead of creating them directly.CommonServiceLocator.1.0
to provide access to containers from different vendors in a container-agnostic manner.IInteceptorCreationStrategy
. Create two implementations:InstantiateInterceptorDirectlyCreationStrategy
andResolveInterceptorFromContainerCreationStrategy
.MasterProxy
class to select appropriate strategy of how to create interceptor isntances.AutofacAspectModule.RegistrationActivating
hook. Wrap Autofac container instance in a service locator adapter and pass it to MasterProxy.In several next commits:
1f58e6d: Add support for
Snap.CastleWindsor
to keep and resolve aspects from container.edd2530: Add support for
Snap.StructureMap
to keep and resolve aspects from container.33f3d2b: Add support for
Snap.Ninject
to keep and resolve aspects from container.92555a2: Add support for
LinFu
to keep and resolve aspects from container.FIX for LinFu:
33f87af
Change LinFu aspect post processing behavior not to intercept types which implement
IInterceptor
. Inteceptors could not be intercepted too.70564b2
When service is not registered in container and being asken,
NullReferenceException
is thrown inAspectPostProcessor
class due to IServiceRequestResult.ActualResult is null.Fix to do nothing in AspectPostProcessor class if IServiceRequestResult.ActualResult is null.
No activity was in upstream master branch since I've forked (samoshkin:keep-aspects-in-container branch is fast-forward from TylerBrinks:master).
Well, seems that's all. I'm looking forward for your response.