コード例 #1
0
        private void ProcessRegistrationDefinition <T1, T2, T3>(RegistrationDefinition definition,
                                                                IRegistrationBuilder <T1, T2, T3> registration)
        {
            if (definition.ExportKey == null)
            {
                registration.As(definition.ExportType);
            }
            else
            {
                registration.Keyed(definition.ExportKey, definition.ExportType);
            }

            switch (definition.RegistrationLifestyle)
            {
            case RegistrationLifestyle.Singleton:
                registration.SingleInstance();
                break;

            case RegistrationLifestyle.SingletonPerScope:
                registration.InstancePerLifetimeScope();
                break;

            case RegistrationLifestyle.SingletonPerNamedScope:
                registration.InstancePerMatchingLifetimeScope(definition.LifestyleInformation);
                break;
            }

            if (definition.Metadata != null)
            {
                foreach (var kvp in definition.Metadata)
                {
                    registration.WithMetadata(kvp.Key.ToString(), kvp.Value);
                }
            }

            if (definition.MemberInjectionList != null)
            {
                foreach (var injectionInfo in definition.MemberInjectionList)
                {
                    switch (injectionInfo.InjectionType)
                    {
                    case MemberInjectionType.Field:
                        throw new Exception("Field injection is not supported out of the box for autofac");

                    case MemberInjectionType.Method:
                        throw new Exception("Method injection is not supported out of the box for autofac");

                    case MemberInjectionType.Property:
                        registration.PropertiesAutowired();
                        break;
                    }
                }
            }
        }
コード例 #2
0
        private void ProcessNonGenericRegistration(RegistrationDefinition definition)
        {
            var registration = _builder.RegisterType(definition.ActivationType);

            ProcessRegistrationDefinition(definition, registration);
        }