public static IContainer LetThereBeIoC(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None, Action <ContainerBuilder> preHooks = null) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(Constants.ServiceAssembly); try { var sw = Stopwatch.StartNew(); if (preHooks != null) { preHooks(builder); } var container = builder.Build(containerBuildOptions); sw.Stop(); container.Resolve <ILogger>().Information("Container built in {ElapsedTime} seconds", sw.Elapsed.TotalSeconds); return(container); } catch (Exception exc) { if (Debugger.IsAttached) { Debugger.Break(); } Log.Fatal(exc, "Container failed to build"); } return(null); }
public static IContainer LetThereBeIoC(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(AppDomainScanner.MyAssemblies); return(builder.Build(containerBuildOptions)); }
public static IContainer LetThereBeIoC(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(IoC).Assembly); return(builder.Build(containerBuildOptions)); }
public void WhenNoStartIsSpecified_StartableComponentsAreIgnored() { const ContainerBuildOptions buildOptions = ContainerBuildOptions.IgnoreStartableComponents; var started = WasStartInvoked(buildOptions); Assert.False(started); }
public static IContainer ConstructContainer(ContainerBuildOptions containerBuildOptions) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(AppBootstrapper).Assembly); return(builder.Build(containerBuildOptions)); }
public void WhenTheContainerIsBuilt_StartableComponentsAreStarted() { const ContainerBuildOptions buildOptions = ContainerBuildOptions.None; var started = WasStartInvoked(buildOptions); Assert.True(started); }
internal static IContainer CreateContainer(ContainerBuildOptions options) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(Startup).Assembly); container = builder.Build(options); return container; }
public new IContainer Build(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None) { var container = base.Build(containerBuildOptions); startup.ConfigureCommands(container); return(container); }
internal static IContainer CreateContainer(ContainerBuildOptions options) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(Startup).Assembly); container = builder.Build(options); return(container); }
public FakeAutofacServiceProviderFactory( ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None, Action <ContainerBuilder>?configurationActionOnBefore = null, Action <ContainerBuilder>?configurationActionOnAfter = null) { _configurationActionOnAfter = configurationActionOnAfter; AutofacServiceProviderFactory = new AutofacServiceProviderFactory(containerBuildOptions, configurationActionOnBefore); }
private static bool WasStartInvoked(ContainerBuildOptions buildOptions) { var startable = Mocks.GetStartable(); var builder = new ContainerBuilder(); builder.RegisterInstance(startable).As <IStartable>(); builder.Build(buildOptions); return(startable.StartCount > 0); }
public IContainer Build(ContainerBuildOptions options) { Container componentContext = new Container(); this.Build(componentContext.ComponentRegistry, (options & ContainerBuildOptions.ExcludeDefaultModules) != ContainerBuildOptions.Default); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.Default) { StartStartableComponents(componentContext); } return(componentContext); }
/// <summary> /// Create a new container with the component registrations that have been made. /// </summary> /// <param name="options">Options that influence the way the container is initialised.</param> /// <remarks> /// Build can only be called once per <see cref="ContainerBuilder"/> /// - this prevents ownership issues for provided instances. /// Build enables support for the relationship types that come with Autofac (e.g. /// Func, Owned, Meta, Lazy, IEnumerable.) To exclude support for these types, /// first create the container, then call Update() on the builder. /// </remarks> /// <returns>A new container with the configured component registrations.</returns> public IContainer Build(ContainerBuildOptions options = ContainerBuildOptions.None) { var result = new Container(); Build(result.ComponentRegistry, (options & ContainerBuildOptions.ExcludeDefaultModules) != ContainerBuildOptions.None); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) { StartStartableComponents(result); } return(result); }
/// <summary> /// Initializes the <see cref="ViewModelLocator"/> with the given /// <paramref name="containerBuilder"/> and registers <see cref="INavigationService"/> /// for Mvvm navigation. /// </summary> /// <param name="containerBuilder"></param> public static void Init(ContainerBuilder containerBuilder, ContainerBuildOptions options = ContainerBuildOptions.None) { containerBuilder .RegisterType <NavigationService>() .As <INavigationService>() .UsingConstructor(Type.EmptyTypes); var iocAdaptor = new IocAdaptor(containerBuilder, options); Container = iocAdaptor.container; ViewModelLocator.Ioc = iocAdaptor; }
public void Update(IContainer container, ContainerBuildOptions options) { // Issue #462: 在这里添加ContainerBuildOptions参数作为重载而不是一个可选参数来避免方法绑定问题。在版本4.0或稍后我们应该将此重构为可选参数. if (container == null) { throw new ArgumentNullException(nameof(container)); } Update(container.ComponentRegistry); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) { StartStartableComponents(container); } }
static bool WasStartInvoked(ContainerBuildOptions buildOptions) { var started = false; var startable = new Mock <IStartable>(); startable.Setup(s => s.Start()) .Callback(() => started = true); var builder = new ContainerBuilder(); builder.RegisterInstance(startable.Object); builder.Build(buildOptions); return(started); }
internal static IContainer CreateContainer(ContainerBuildOptions options) { var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterAssemblyModules(typeof(BusModule).Assembly); builder.RegisterModelBinders(Assembly.GetExecutingAssembly()); builder.RegisterModelBinderProvider(); builder.RegisterModule<AutofacWebTypesModule>(); builder.RegisterSource(new ViewRegistrationSource()); builder.RegisterFilterProvider(); container = builder.Build(options); return container; }
public static IContainer LetThereBeIoC(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None, Action <ContainerBuilder> preBuildHook = null) { var builder = new ContainerBuilder(); var thisAssembly = typeof(IoC).Assembly; builder.RegisterAssemblyModules(thisAssembly); if (preBuildHook != null) { preBuildHook(builder); } return(builder.Build(containerBuildOptions)); }
internal static IContainer CreateContainer(ContainerBuildOptions options) { var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterAssemblyModules(typeof(BusModule).Assembly); builder.RegisterModelBinders(Assembly.GetExecutingAssembly()); builder.RegisterModelBinderProvider(); builder.RegisterModule <AutofacWebTypesModule>(); builder.RegisterSource(new ViewRegistrationSource()); builder.RegisterFilterProvider(); container = builder.Build(options); return(container); }
public void Update(IContainer container, ContainerBuildOptions options) { // Issue #462: The ContainerBuildOptions parameter is added here as an overload // rather than an optional parameter to avoid method binding issues. In version // 4.0 or later we should refactor this to be an optional parameter. if (container == null) { throw new ArgumentNullException(nameof(container)); } Update(container.ComponentRegistry); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) { StartStartableComponents(container); } }
/// <summary> /// Create a new container with the component registrations that have been made. /// </summary> /// <param name="options">Options that influence the way the container is initialised.</param> /// <remarks> /// Build can only be called once per <see cref="ContainerBuilder"/> /// - this prevents ownership issues for provided instances. /// Build enables support for the relationship types that come with Autofac (e.g. /// Func, Owned, Meta, Lazy, IEnumerable.) To exclude support for these types, /// first create the container, then call Update() on the builder. /// </remarks> /// <returns>A new container with the configured component registrations.</returns> public IContainer Build(ContainerBuildOptions options = ContainerBuildOptions.None) { var result = new Container(Properties); Build(result.ComponentRegistry, (options & ContainerBuildOptions.ExcludeDefaultModules) != ContainerBuildOptions.None); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) { StartStartableComponents(result); } foreach (var buildCallback in _buildCallbacks) { buildCallback(result); } return(result); }
/// <summary> /// Create a new container with the component registrations that have been made. /// </summary> /// <param name="options">Options that influence the way the container is initialised.</param> /// <remarks> /// Build can only be called once per <see cref="ContainerBuilder"/> /// - this prevents ownership issues for provided instances. /// Build enables support for the relationship types that come with Autofac (e.g. /// Func, Owned, Meta, Lazy, IEnumerable.) To exclude support for these types, /// first create the container, then call Update() on the builder. /// </remarks> /// <returns>A new container with the configured component registrations.</returns> public IContainer Build(ContainerBuildOptions options = ContainerBuildOptions.None) { var result = new Container(Properties); result.ComponentRegistry.Properties[MetadataKeys.ContainerBuildOptions] = options; Build(result.ComponentRegistry, (options & ContainerBuildOptions.ExcludeDefaultModules) != ContainerBuildOptions.None); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) { StartableManager.StartStartableComponents(result); } var buildCallbacks = GetBuildCallbacks(); foreach (var buildCallback in buildCallbacks) { buildCallback(result); } return(result); }
public static IContainer LetThereBeIoC(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None, params Assembly[] assemblies) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(assemblies); try { var sw = Stopwatch.StartNew(); var container = builder.Build(containerBuildOptions); sw.Stop(); Log.Information("Container built in {Elapsed}", sw.Elapsed); return(container); } catch (Exception exc) { Log.Fatal(exc, "Container failed to build: {Message}", exc.Message); } return(null); }
/// <summary> /// Create a new container with the component registrations that have been made. /// </summary> /// <param name="options">Options that influence the way the container is initialised.</param> /// <remarks> /// Build can only be called once per <see cref="ContainerBuilder"/> /// - this prevents ownership issues for provided instances. /// Build enables support for the relationship types that come with Autofac (e.g. /// Func, Owned, Meta, Lazy, IEnumerable.) To exclude support for these types, /// first create the container, then call Update() on the builder. /// </remarks> /// <returns>A new container with the configured component registrations.</returns> public IContainer Build(ContainerBuildOptions options = ContainerBuildOptions.None) { Properties[MetadataKeys.ContainerBuildOptions] = options; #pragma warning disable CA2000 // Dispose objects before losing scope ComponentRegistryBuilder.Register(new SelfComponentRegistration()); #pragma warning restore CA2000 // Dispose objects before losing scope Build(ComponentRegistryBuilder, (options & ContainerBuildOptions.ExcludeDefaultModules) != ContainerBuildOptions.None); var componentRegistry = ComponentRegistryBuilder.Build(); var result = new Container(componentRegistry); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) { StartableManager.StartStartableComponents(Properties, result); } // Run any build callbacks. BuildCallbackManager.RunBuildCallbacks(result); return(result); }
public static void LetThereBeIoC(ContainerBuildOptions options = ContainerBuildOptions.None) { var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(typeof(MapViewModel).GetTypeInfo().Assembly) .InNamespaceOf<MapViewModel>() .Where(t => !t.GetTypeInfo().IsAbstract) .AsSelf() .InstancePerDependency(); builder.RegisterAssemblyTypes(typeof(MapView).GetTypeInfo().Assembly) .Where(t => t.Namespace != null && t.Namespace.Contains("Views")) .Where(t => t.Name.EndsWith("View")) .AsSelf() .InstancePerDependency(); builder.RegisterType<EventAggregator>().AsImplementedInterfaces().SingleInstance(); builder.RegisterModule<EventAggregationSubscriptionModule>(); builder.Register(c => new FrameAdapter(Frame)).AsImplementedInterfaces().InstancePerDependency(); builder.RegisterType<MapItem>().AsSelf().InstancePerDependency(); Container = builder.Build(options); }
public static IContainer LetThereBeIoC(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None, Action<ContainerBuilder> preHooks = null) { var builder = new ContainerBuilder(); builder.RegisterModule<FluentSchedulerModule>(); builder.RegisterModule<JsonSerializerModule>(); builder.RegisterModule<LoggerModule>(); builder.RegisterModule<SignalRModule>(); try { var sw = Stopwatch.StartNew(); if (preHooks != null) preHooks(builder); var container = builder.Build(containerBuildOptions); sw.Stop(); container.Resolve<ILogger>().Information("Container built in {Elapsed}", sw.Elapsed); return container; } catch (Exception exc) { Log.Fatal(exc, "Container failed to build: {Message}", exc.Message); } return null; }
/// <summary> /// 创建IoC容器 /// </summary> /// <returns></returns> public OrzAutofac BuildContainer(ContainerBuildOptions options = ContainerBuildOptions.None) { Container = ContainerBuilder.Build(options); return(this); }
/// <summary> /// Create a new IOC Kernel container that will start the binding process. /// </summary> /// <param name="buildOptions"></param> /// <returns></returns> public static IIocKernelBuilder Initialize(ContainerBuildOptions buildOptions = ContainerBuildOptions.None) { return(new IocKernelBuilder(buildOptions, new DependencyFactory(InspectMethod.Instance))); }
public InitializeOptions(Assembly[] collection, IModule[] modules, ContainerBuildOptions buildOptions) { this.AssembliesToScan = collection; this.Modules = modules; this.BuildOptions = buildOptions; }
public static IContainer ConstructContainer(ContainerBuildOptions containerBuildOptions) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(AppBootstrapper).Assembly); return builder.Build(containerBuildOptions); }
/// <summary> /// Injected Constructor where DotNetStarter creates the container /// </summary> /// <param name="containerBuilder"></param> /// <param name="options"></param> public AutofacLocatorRegistryFactory(ContainerBuilder containerBuilder, ContainerBuildOptions options) { _containerBuilder = containerBuilder; _containerBuilderOptions = options; }
/// <summary> /// Initializes a new instance of the <see cref="AutofacServiceProviderFactory"/> class. /// </summary> /// <param name="containerBuildOptions">The container options to use when building the container.</param> /// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/> that adds component registrations to the container.</param> public CustomAutofacServiceProviderFactory( ContainerBuildOptions containerBuildOptions, Action <ContainerBuilder> configurationAction = null) : this(configurationAction) =>
/// <summary> /// Initializes a new instance of the <see cref="App"/> class. /// </summary> /// <param name="buildOptions"> /// The build options. /// </param> public App(ContainerBuildOptions buildOptions) { this.ContainerBuildOptions = buildOptions; this.ContainerBuilder = new ContainerBuilder(); }
/// <summary> /// Create a new container with the component registrations that have been made. /// </summary> /// <param name="options">Options that influence the way the container is initialised.</param> /// <remarks> /// Build can only be called once per <see cref="ContainerBuilder"/> /// - this prevents ownership issues for provided instances. /// Build enables support for the relationship types that come with Autofac (e.g. /// Func, Owned, Meta, Lazy, IEnumerable.) To exclude support for these types, /// first create the container, then call Update() on the builder. /// </remarks> /// <returns>A new container with the configured component registrations.</returns> public IContainer Build(ContainerBuildOptions options = ContainerBuildOptions.None) { var result = new Container(); Build(result.ComponentRegistry, (options & ContainerBuildOptions.ExcludeDefaultModules) != ContainerBuildOptions.None); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) StartStartableComponents(result); return result; }
public static IContainer ConstructContainer(ContainerBuildOptions containerBuildOptions) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof (Repository<>).Assembly); return builder.Build(containerBuildOptions); }
public void Update(IContainer container, ContainerBuildOptions options) { // Issue #462: The ContainerBuildOptions parameter is added here as an overload // rather than an optional parameter to avoid method binding issues. In version // 4.0 or later we should refactor this to be an optional parameter. if (container == null) throw new ArgumentNullException("container"); Update(container.ComponentRegistry); if ((options & ContainerBuildOptions.IgnoreStartableComponents) == ContainerBuildOptions.None) StartStartableComponents(container); }
private IContainer Build(ContainerBuildOptions options) { return(Builder.Build(options)); }
/// <summary> /// Constructor /// </summary> /// <param name="builder">The Autofac builder to use</param> /// <param name="options">Container build options, defaults to ContainerBuildOptions.None</param> public LazyAutofacApplicationFrameworkDependencyResolver(ContainerBuilder builder, ContainerBuildOptions options = ContainerBuildOptions.None) : base(builder) { _container = new Lazy <IContainer>(() => Build(options), LazyThreadSafetyMode.PublicationOnly); }
public IAutofacBuilder Options(ContainerBuildOptions buildOptions) { _options.BuildOptions = buildOptions; return this; }
public static void LetThereBeIoC(ContainerBuildOptions containerBuildOptions = ContainerBuildOptions.None) { Container = ConstructContainer(containerBuildOptions); }