Example #1
0
        private void AutofacContainerBuilder_Building(object sender, AppContainerBuilderBuildEventArgs e)
        {
            AutofacContainerBuilder autofacContainerBuilder = (AutofacContainerBuilder)sender;

            foreach (var method in methods)
            {
                autofacContainerBuilder.RemoveComponentByComponentType(method.Method.ReturnType);
                autofacContainerBuilder.RegisterByCreator(cm =>
                {
                    ParameterInfo[] ps = method.Method.GetParameters();
                    if (ps.Length == 0)
                    {
                        return(method.Method.Invoke(method.Target, null));
                    }
                    object[] values = new object[ps.Length];
                    for (int i = 0; i < ps.Length; i++)
                    {
                        Type pType   = ps[i].ParameterType;
                        object value = cm.CreateComponent(pType);
                        values[i]    = value;
                    }
                    return(method.Method.Invoke(method.Target, values));
                }, method.Method.ReturnType);
            }
        }
Example #2
0
        public void Prepare(AppSetup setup)
        {
            AutofacContainerBuilder autofacContainerBuilder
                = setup.GetAppContainerBuilder <AutofacContainerBuilder>();

            autofacContainerBuilder.Building += AutofacContainerBuilder_Building;
        }
        private void AutofacContainerBuilder_Building(object sender, AppContainerBuilderBuildEventArgs e)
        {
            AutofacContainerBuilder autofacContainerBuilder = (AutofacContainerBuilder)sender;
            AppSetup setup   = e.AppSetup;
            JObject  jObject = null;

            if (File.Exists(setup.ConfigFilePath))
            {
                string json = File.ReadAllText(setup.ConfigFilePath);
                jObject = JObject.Parse(json);
            }

            this.configTypeToRegistionMap
            .ForEach(x =>
            {
                string section   = x.Value.Section;
                JToken subObject = jObject?.GetValue(section);
                object configValue;

                if (subObject == null)
                {
                    configValue = x.Value.CreateDefaultInstance();
                }
                else
                {
                    configValue = subObject.ToObject(x.Key);
                }

                autofacContainerBuilder.RegisterInstance(configValue);
            });

            this.ConfigObjectRegisted?.Invoke(this, new AppContainerBuilderBuildEventArgs(setup));
        }
Example #4
0
        private void AutofacContainerBuilder_Building(object sender, AppContainerBuilderBuildEventArgs e)
        {
            AutofacContainerBuilder autofacContainerBuilder = (AutofacContainerBuilder)sender;
            ContainerBuilder        containerBuilder        = autofacContainerBuilder.AutofacContainerBuilderInstance;

            this.assemblies.ForEach(x =>
            {
                containerBuilder.RegisterApiControllers(x);
            });
        }
        private void AutofacContainerBuilder_Building(object sender, AppContainerBuilderBuildEventArgs e)
        {
            ProxyGenerator          proxyGenerator = new ProxyGenerator();
            AutofacContainerBuilder autofacContainerBuilder
                = (AutofacContainerBuilder)sender;

            foreach (var info in attributeAndTypeInfos)
            {
                autofacContainerBuilder.RegisterByCreator(c =>
                {
                    c.InjectProperties(info.Attribute);

                    ImplementorAttributeExecuteInterceptor interceptor = new ImplementorAttributeExecuteInterceptor(info.Type, (ImplementorAttribute)info.Attribute);
                    var rlt = proxyGenerator.CreateInterfaceProxyWithoutTarget(
                        info.Type,
                        interceptor
                        );
                    return(rlt);
                }, info.Type);
            }
        }