コード例 #1
0
        protected override void AttachToComponentRegistration(Autofac.Core.IComponentRegistry componentRegistry, Autofac.Core.IComponentRegistration registration)
        {
            base.AttachToComponentRegistration(componentRegistry, registration);

            if (!registration.Activator.LimitType.ToString().StartsWith("TryAspNetCore"))
            {
                return;
            }

            // It will be good for the register interceptor
            // componentRegistry.Registered += (sender, e) =>
            // {
            //     if (!e.ComponentRegistration.Activator.LimitType.ToString().StartsWith("TryAspNetCore"))
            //         return;

            //     Console.WriteLine($"Registered: { e.ComponentRegistration.Activator.LimitType.ToString() }");
            // };

            // registration.Activating += (sender, e) =>
            // {
            //     if (!e.Instance.GetType().ToString().StartsWith("TryAspNetCore"))
            //         return;
            //     Console.WriteLine($"Activating: { e.Instance.GetType().ToString() }");
            // };

            // registration.Activated += (sender, e) =>
            // {
            //     Console.WriteLine("ACtivated");
            // };
        }
コード例 #2
0
 protected override void AttachToComponentRegistration(Autofac.Core.IComponentRegistry componentRegistry, Autofac.Core.IComponentRegistration registration)
 {
     if (typeof(IDataServicesProvider).IsAssignableFrom(registration.Activator.LimitType))
     {
         var propertyInfo = registration.Activator.LimitType.GetProperty("ProviderName", BindingFlags.Static | BindingFlags.Public);
         if (propertyInfo != null)
         {
             registration.Metadata["ProviderName"] = propertyInfo.GetValue(null, null);
         }
     }
 }
コード例 #3
0
        protected override void AttachToComponentRegistration(Autofac.Core.IComponentRegistry componentRegistry, Autofac.Core.IComponentRegistration registration)
        {
            var needsCacheManager = registration.Activator.LimitType
                                    .GetConstructors()
                                    .Any(x => x.GetParameters()
                                         .Any(xx => xx.ParameterType == typeof(ICacheManager)));

            if (needsCacheManager)
            {
                registration.Preparing += (sender, e) => {
                    var parameter = new TypedParameter(
                        typeof(ICacheManager),
                        e.Context.Resolve <ICacheManager>(new TypedParameter(typeof(Type), registration.Activator.LimitType)));
                    e.Parameters = e.Parameters.Concat(new[] { parameter });
                };
            }
        }