public AutomaticFactoryProxy(Type factoryType, Container container) : base(factoryType) { this.factoryType = factoryType; this.container = container; this.helper = AutomaticParameterizedFactoryExtensions.GetBehavior(container); }
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); }
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); }
private static void SetBehavior(Container container, AutomaticParameterizedFactoriesHelper behavior) { container.ContainerScope.SetItem(typeof(AutomaticParameterizedFactoriesHelper), behavior); }