示例#1
0
 public AutomaticFactoryProxy(Type factoryType, Container container)
     : base(factoryType)
 {
     this.factoryType = factoryType;
     this.container   = container;
     this.helper      = AutomaticParameterizedFactoryExtensions.GetBehavior(container);
 }
示例#2
0
        public static void EnableAutomaticParameterizedFactories(this ContainerOptions options)
        {
            if (GetBehavior(options.Container) != null)
            {
                throw new InvalidOperationException("Already called.");
            }

            var behavior = new AutomaticParameterizedFactoriesHelper(options);

            options.DependencyInjectionBehavior = behavior;

            SetBehavior(options.Container, behavior);
        }
示例#3
0
        public static void RegisterFactoryProduct <TService, TImplementation>(this Container container,
                                                                              Lifestyle lifestyle = null)
            where TImplementation : class, TService
            where TService : class
        {
            AutomaticParameterizedFactoriesHelper behavior = GetBehavior(container);

            if (behavior is null)
            {
                throw new InvalidOperationException(
                          "Make sure you call container.Options.EnableAutomaticParameterizedFactories() first.");
            }

            behavior.RegisterFactoryProduct(typeof(TService), typeof(TImplementation));

            lifestyle = lifestyle ?? container.Options.LifestyleSelectionBehavior
                        .SelectLifestyle(typeof(TImplementation));

            container.Register <TService, TImplementation>(lifestyle);
        }
示例#4
0
 private static void SetBehavior(Container container, AutomaticParameterizedFactoriesHelper behavior)
 {
     container.ContainerScope.SetItem(typeof(AutomaticParameterizedFactoriesHelper), behavior);
 }