public static AdaptedContainerBuilderOptions <TTenant> WithStructureMap <TTenant>(this ContainerBuilderOptions <TTenant> options,
                                                                                          Action <TTenant, IServiceCollection> configureTenant)
            where TTenant : class
        {
            var adaptorFactory = new Func <ITenantContainerAdaptor>(() =>
            {
                // host level container.
                var container = new StructureMap.Container();
                container.Populate(options.Builder.Services);
                var adaptedContainer = container.GetInstance <ITenantContainerAdaptor>();
                // add ITenantContainerBuilder<TTenant> service to the host container
                // This service can be used to build a child container (adaptor) for a particular tenant, when required.
                container.Configure(_ =>
                                    _.For <ITenantContainerBuilder <TTenant> >()
                                    .Use(new TenantContainerBuilder <TTenant>(adaptedContainer, configureTenant))
                                    );

                var adaptor = container.GetInstance <ITenantContainerAdaptor>();
                return(adaptor);
            });

            var adapted = new AdaptedContainerBuilderOptions <TTenant>(options, adaptorFactory);

            options.Builder.Services.TryAddScoped((_) => adapted);

            return(adapted);
        }
        public static AdaptedContainerBuilderOptions <TTenant> WithStructureMap <TTenant>(
            this ContainerBuilderOptions <TTenant> options,
            Action <TTenant, IServiceCollection> configureTenant)
            where TTenant : class
        {
            var adaptorFactory = new Func <ITenantContainerAdaptor>(() =>
            {
                // host level container.
                var container = new StructureMap.Container();
                container.Populate(options.Builder.Services);
                var adaptedContainer = container.GetInstance <ITenantContainerAdaptor>();

                var containerEventsPublisher = container.TryGetInstance <ITenantContainerEventsPublisher <TTenant> >();
                // add ITenantContainerBuilder<TTenant> service to the host container
                // This service can be used to build a child container (adaptor) for a particular tenant, when required.
                var defaultServices = options.DefaultServices;
                container.Configure(_ =>
                                    _.For <ITenantContainerBuilder <TTenant> >()
                                    .Use(new TenantContainerBuilder <TTenant>(defaultServices, adaptedContainer, configureTenant, containerEventsPublisher))
                                    );

                // NOTE: Im not sure why I was resolving ITenantContainerAdaptor twice, changed to just return previous instance.
                //var adaptor = container.GetInstance<ITenantContainerAdaptor>();
                //return adaptor;
                return(adaptedContainer);
            });

            var adapted = new AdaptedContainerBuilderOptions <TTenant>(options, adaptorFactory);

            return(adapted);
        }
示例#3
0
    public static ContainerBuilderOptions<TTenant> HasModules<TTenant>(this AdaptedContainerBuilderOptions<TTenant> options, Action<ModuleOptionsBuilder<TTenant>> configure)
 where TTenant : class
        //    where TModule : IModule
    {
        var builder = new ModuleOptionsBuilder<TTenant>(options);
        configure(builder);
        return options.ContainerBuilderOptions;
    }
 public static AdaptedContainerBuilderOptions <TTenant> OnHostContainerStartup <TTenant>(
     this AdaptedContainerBuilderOptions <TTenant> @this,
     Action <IServiceProvider> callback)
     where TTenant : class
 {
     @this.OnHostContainerBuilt = callback;
     return(@this);
 }
        public static AdaptedContainerBuilderOptions <TTenant> ConfigureHostContainer <TTenant>(
            this AdaptedContainerBuilderOptions <TTenant> @this,
            Action <ConfigurationExpression> configurationAction)
            where TTenant : class
        {
            @this.ContainerBuilderOptions.Builder.Services
            .AddTransient <IStructureMapHostContainerConfigurator>((_) => new StructureMapHostContainerConfigurator {
                ConfigureHostContainer = configurationAction
            });

            return(@this);
        }
示例#6
0
        public static AdaptedContainerBuilderOptions <TTenant> Autofac <TTenant>(
            this ContainerBuilderOptions <TTenant> options,
            Action <TTenant, IServiceCollection> configureTenant)
            where TTenant : class
        {
            Func <ITenantContainerAdaptor> adaptorFactory = new Func <ITenantContainerAdaptor>(() =>
            {
                // host level container.
                ContainerBuilder builder = new ContainerBuilder();
                builder.Populate(options.Builder.Services);
                builder.AddDotnettencyContainerServices();


                // Build the root container.
                IContainer container = builder.Build();
                ITenantContainerAdaptor adaptedContainer = container.Resolve <ITenantContainerAdaptor>();

                // Get the service that allows us to publish events relating to tenant container events.
                container.TryResolve <ITenantContainerEventsPublisher <TTenant> >(out ITenantContainerEventsPublisher <TTenant> containerEventsPublisher);

                // Update the root container with a service that can be used to build per tenant container!
                ContainerBuilder updateBuilder = new ContainerBuilder();
                var defaultServices            = options.DefaultServices;
                updateBuilder.RegisterInstance(new TenantContainerBuilder <TTenant>(defaultServices, adaptedContainer, configureTenant, containerEventsPublisher)).As <ITenantContainerBuilder <TTenant> >();
                updateBuilder.Update(container);

                return(adaptedContainer);
                //ITenantContainerAdaptor adaptor = container.Resolve<ITenantContainerAdaptor>();
                //return adaptor;

                // return adaptedContainer;
            });

            AdaptedContainerBuilderOptions <TTenant> adapted = new AdaptedContainerBuilderOptions <TTenant>(options, adaptorFactory);

            return(adapted);
        }
示例#7
0
 public ModuleOptionsBuilder(AdaptedContainerBuilderOptions<TTenant> parentOptions)
 {
     _parentOptions = parentOptions;
 }