Example #1
0
        private static ContainerInterceptorWrapper CreateInterceptorWrapper()
        {
            //bool ShouldCache(RegistrationContext reg) => reg.ToType.GetMethods()
            //.Select(m => m.GetCustomAttribute<CachingAttribute>(false))
            //.Any(a => a != null);

            bool ShouldCache = false;

            bool ShouldMeasure(RegistrationContext reg) => reg.Attribute.LegacyMeasured;

            var wrapper = new ContainerInterceptorWrapper();

            //wrapper.RegisterInterceptor(CachingInterceptor.GenerateInterfaceProxy, ShouldCache);
            //wrapper.RegisterInterceptor(MeasurementInterceptor.GenerateInterfaceProxy, ShouldMeasure);
            return(wrapper);
        }
Example #2
0
        public static void RegisterByAttribute(this IUnityContainer container, bool mockMode, params Assembly[] assemblies)
        {
            _container = container;
            _collectionItemsForType = new Dictionary <Type, List <ResolutionItem> >();
            _keysForTypes           = new Dictionary <Type, HashSet <string> >();
            _interceptorWrapper     = CreateInterceptorWrapper();
            _componentResolver      = new UnityComponentResolver(container);

            var scanAndRegisterActions = new List <IList <string> >
            {
                ScanAndRegister <RegisterSingletonAttribute, ContainerControlledLifetimeManager>(mockMode, assemblies),
                ScanAndRegister <RegisterPerRequestAttribute, HttpContextLifetimeManager>(mockMode, assemblies),
                ScanAndRegister <RegisterTransientAttribute, TransientLifetimeManager>(mockMode, assemblies),
            };

            var errorMessages = scanAndRegisterActions.SelectMany(msg => msg).ToList();

            ContainerAttributeUtils.ThrowIfError(errorMessages);
        }