Example #1
0
 internal StashboxContainer(IStashboxContainer parentContainer, IContainerExtensionManager containerExtensionManager,
                            IResolverSelector resolverSelector, IContainerConfigurator containerConfigurator, IDecoratorRepository decoratorRepository)
     : this(containerExtensionManager, resolverSelector, containerConfigurator, decoratorRepository)
 {
     this.ParentContainer = parentContainer;
     this.containerExtensionManager.ReinitalizeExtensions(this.ContainerContext);
 }
 public void Compose(IStashboxContainer container)
 {
     if (this.Test != 5)
     {
         Assert.True(false, "Dependency not resolved");
     }
 }
 public void Compose(IStashboxContainer container)
 {
     if (this.Test == null)
     {
         Assert.Fail("Dependency not resolved");
     }
 }
Example #4
0
        public void ConfigureContainer(IStashboxContainer container)
        {
            var proxyBuilder = new DefaultProxyBuilder();

            container.Register <IInterceptor, NoInterceptor>();
            container.RegisterDecorator <ILevel2Service>(proxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(typeof(ILevel2Service), Array.Empty <Type>(), ProxyGenerationOptions.Default));
            container.RegisterDecorator <ILevel2bService>(proxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(typeof(ILevel2bService), Array.Empty <Type>(), ProxyGenerationOptions.Default));
            container.RegisterDecorator <ILevel3Service>(proxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(typeof(ILevel3Service), Array.Empty <Type>(), ProxyGenerationOptions.Default));
        }
Example #5
0
 internal ContainerContext(IRegistrationRepository registrationRepository, IStashboxContainer container,
                           IResolutionStrategy resolutionStrategy, IContainerConfigurator containerConfigurator, IDecoratorRepository decoratorRepository)
 {
     this.ResolutionStrategy     = resolutionStrategy;
     this.RegistrationRepository = registrationRepository;
     this.Container             = container;
     this.ContainerConfigurator = containerConfigurator;
     this.DecoratorRepository   = decoratorRepository;
 }
Example #6
0
        public void Compose(IStashboxContainer container)
        {
            container.RegisterAssemblyContaining <IQuartzConfiguration>();

            // Register Quartz
            var quartz = container.Resolve <IQuartzConfiguration>();

            quartz.Scheduler.JobFactory = new QuartzJobFactory(container);
            quartz.Scheduler.ListenerManager.AddJobListener(container.Resolve <IJobListener>());
        }
        /// <summary>
        /// Adds <see cref="StashboxContainer"/> as the default dependency resolver and the default <see cref="IHubActivator"/>, also registers the available <see cref="IHub"/> and <see cref="PersistentConnection"/> implementations.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="types">The types.</param>
        /// <returns>The container.</returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer AddSignalRWithTypes(this IStashboxContainer container, params Type[] types)
        {
            Shield.EnsureNotNull(container, nameof(container));

            container.RegisterSingleton <Microsoft.AspNet.SignalR.IDependencyResolver, StashboxDependencyResolver>();
            container.RegisterSingleton <IHubActivator, StashboxHubActivator>();
            GlobalHost.DependencyResolver = container.Resolve <Microsoft.AspNet.SignalR.IDependencyResolver>();

            return(container.RegisterHubs(types).RegisterPersistentConnections(types));
        }
Example #8
0
 public override void Prepare()
 {
     this.container = CreateServiceCollection().CreateBuilder();
     this.RegisterBasic();
     this.RegisterPropertyInjection();
     this.RegisterOpenGeneric();
     this.RegisterConditional();
     this.RegisterMultiple();
     this.RegisterInterceptor();
 }
        /// <summary>
        /// Registers the <see cref="IHub"/> implementations found in the given types.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="types">The types.</param>
        /// <returns>The container.</returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer RegisterHubs(this IStashboxContainer container, params Type[] types)
        {
            Shield.EnsureNotNull(container, nameof(container));

            if (types.Length > 0)
            {
                container.RegisterTypes(types, type => typeof(IHub).IsAssignableFrom(type), context => context.WithoutDisposalTracking());
            }

            return(container);
        }
Example #10
0
 /// <summary>
 /// Constructs a <see cref="ContainerContext"/>
 /// </summary>
 /// <param name="registrationRepository">The repository of the registrations.</param>
 /// <param name="container">The container itself.</param>
 /// <param name="resolutionStrategy">The resolution strategy.</param>
 /// <param name="metaInfoRepository">The meta information repository.</param>
 /// <param name="delegateRepository">Repository of the compiled delegates.</param>
 internal ContainerContext(IRegistrationRepository registrationRepository, IStashboxContainer container,
     IResolutionStrategy resolutionStrategy, ExtendedImmutableTree<MetaInfoCache> metaInfoRepository,
     ExtendedImmutableTree<Func<ResolutionInfo, object>> delegateRepository)
 {
     this.RegistrationRepository = registrationRepository;
     this.Container = container;
     this.ResolutionStrategy = resolutionStrategy;
     this.MetaInfoRepository = metaInfoRepository;
     this.DelegateRepository = delegateRepository;
     this.Bag = new ConcurrentKeyValueStore<object, object>();
 }
Example #11
0
        public static void SetupDependencies(IStashboxContainer container, ILogger logger)
        {
            container.RegisterInstance(logger);
            container.Register <ILoggerFactory, SerilogLoggerFactory>();
            container.Register(typeof(IValidationTextFormatter <>), typeof(SingleLineFormatter));

            container.RegisterSingleton <ConfigProvider>();
            container.RegisterSingleton <MigoProxyService>();

            container.Register <MainWindowViewModel>();
        }
Example #12
0
        private StashboxContainer(IStashboxContainer parentContainer, ServiceRegistrator serviceRegistrator,
                                  RegistrationBuilder registrationBuilder, ResolutionStrategy resolutionStrategy, ExpressionFactory expressionFactory,
                                  ExpressionBuilder expressionBuilder, ContainerConfigurator containerConfigurator, Action <ContainerConfigurator> config = null)
            : this(expressionFactory, serviceRegistrator, registrationBuilder, containerConfigurator, config)
        {
            this.resolutionStrategy = resolutionStrategy;
            this.expressionBuilder  = expressionBuilder;

            this.ContainerContext = new ContainerContext(parentContainer.ContainerContext, resolutionStrategy,
                                                         expressionFactory, this.containerConfigurator.ContainerConfiguration);
        }
Example #13
0
 internal ContainerContext(IRegistrationRepository registrationRepository, IDelegateRepository delegateRepository,
                           IStashboxContainer container, IResolutionStrategy resolutionStrategy, IContainerConfigurator containerConfigurator,
                           IDecoratorRepository decoratorRepository)
 {
     this.ResolutionStrategy     = resolutionStrategy;
     this.RegistrationRepository = registrationRepository;
     this.DelegateRepository     = delegateRepository;
     this.Container             = container;
     this.Bag                   = new ConcurrentKeyValueStore <object, object>();
     this.ContainerConfigurator = containerConfigurator;
     this.DecoratorRepository   = decoratorRepository;
 }
Example #14
0
        public StashboxAdapter()
        {
            this.container = new StashboxContainer(config => config
                                                   .WithCircularDependencyTracking()
                                                   .WithDisposableTransientTracking()
                                                   .WithMemberInjectionWithoutAnnotation()
                                                   .WithOptionalAndDefaultValueInjection()
                                                   .WithUnknownTypeResolution()
                                                   .WithCircularDependencyWithLazy());

            this.perRequestScope = new StashboxPerRequestScopeProvider(this.container);
        }
Example #15
0
        /// <summary>
        /// Sets a custom <see cref="IFilterProvider"/> which enables property injection in filters.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> or <paramref name="config"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer AddWebApiFilterProviderInjection(this IStashboxContainer container, HttpConfiguration config)
        {
            Shield.EnsureNotNull(container, nameof(container));
            Shield.EnsureNotNull(config, nameof(config));

            container.Register <IFilterProvider, StashboxFilterProvider>(context => context
                                                                         .WithInjectionParameters(new KeyValuePair <string, object>("filterProviders", config.Services.GetServices(typeof(IFilterProvider))
                                                                                                                                    .Cast <IFilterProvider>())));

            config.Services.Clear(typeof(IFilterProvider));

            return(container);
        }
        /// <summary>
        /// Registers the <see cref="PersistentConnection"/> implementations found in the given assemblies.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <returns>The container.</returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer RegisterPersistentConnections(this IStashboxContainer container, params Assembly[] assemblies)
        {
            Shield.EnsureNotNull(container, nameof(container));

            if (assemblies.Length > 0)
            {
                container.RegisterAssemblies(assemblies,
                                             type => typeof(PersistentConnection).IsAssignableFrom(type),
                                             context => context.WithoutDisposalTracking());
            }

            return(container);
        }
Example #17
0
        /// <summary>
        /// Configures the <see cref="IStashboxContainer"/> as the default dependency resolver and sets custom <see cref="IFilterProvider"/> and <see cref="ModelValidatorProvider"/>.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> or <paramref name="config"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer AddWebApi(this IStashboxContainer container, HttpConfiguration config)
        {
            Shield.EnsureNotNull(container, nameof(container));
            Shield.EnsureNotNull(config, nameof(config));

            container.AddWebApiModelValidatorInjection(config);
            container.AddWebApiFilterProviderInjection(config);

            config.DependencyResolver = new StashboxDependencyResolver(container);
            container.RegisterWebApiControllers(config);

            return(container);
        }
Example #18
0
        /// <summary>
        /// Registers the web api controllers into the <see cref="IStashboxContainer"/>.
        /// </summary>
        /// <param name="config">The http configuration.</param>
        /// <param name="container">The container.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> or <paramref name="config"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer RegisterWebApiControllers(this IStashboxContainer container, HttpConfiguration config)
        {
            Shield.EnsureNotNull(container, nameof(container));
            Shield.EnsureNotNull(config, nameof(config));

            var assembliesResolver = config.Services.GetAssembliesResolver();
            var typeResolver       = config.Services.GetHttpControllerTypeResolver();

            container.RegisterTypes(typeResolver.GetControllerTypes(assembliesResolver), null,
                                    context => context.WithLifetime(new ScopedLifetime()));

            return(container);
        }
        private static void RegisterComponents(IStashboxContainer container)
        {
            container.Register <ModelValidatorProvider, StashboxDataAnnotationsModelValidatorProvider>();
            container.Register <ModelValidatorProvider, StashboxModelValidatorProvider>(context =>
                                                                                        context.WithInjectionParameters(new KeyValuePair <string, object>("modelValidatorProviders",
                                                                                                                                                          ModelValidatorProviders.Providers.Where(provider => !(provider is DataAnnotationsModelValidatorProvider)).ToArray())));

            container.Register <IFilterProvider, StashboxFilterAttributeFilterProvider>();
            container.Register <IFilterProvider, StashboxFilterProvider>(context =>
                                                                         context.WithInjectionParameters(new KeyValuePair <string, object>("filterProviders",
                                                                                                                                           FilterProviders.Providers.Where(provider => !(provider is FilterAttributeFilterProvider)).ToArray())));

            RegisterControllers(container);
        }
Example #20
0
        public static HttpApplication AddStashbox(
            this HttpApplication application)
        {
            lock (Lock)
            {
                AttachEvents(application);

                var configuration = GetDefaultConfiguration();

                RootContainer = SetServiceProvider(configuration).RootContainer;

                return(application);
            }
        }
Example #21
0
        public override void Prepare()
        {
            ServiceCollection services = new ServiceCollection();

            this.RegisterAspNetCoreClasses(services);

            this.container = services.CreateBuilder();
            this.RegisterBasic();
            this.RegisterPropertyInjection();
            this.RegisterOpenGeneric();
            this.RegisterConditional();
            this.RegisterMultiple();
            this.RegisterInterceptor();
        }
Example #22
0
 public void Teardown()
 {
     try
     {
         _container?.Dispose();
     }
     catch (Exception)
     {
         // ignored
     }
     finally
     {
         _container = null;
     }
 }
Example #23
0
        /// <summary>
        /// Sets a custom <see cref="ModelValidatorProvider"/> which enables property injection in model validators.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> or <paramref name="config"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer AddWebApiModelValidatorInjection(this IStashboxContainer container, HttpConfiguration config)
        {
            Shield.EnsureNotNull(container, nameof(container));
            Shield.EnsureNotNull(config, nameof(config));

            container.Register <ModelValidatorProvider, StashboxDataAnnotationsModelValidatorProvider>();
            container.Register <ModelValidatorProvider, StashboxModelValidatorProvider>(context => context
                                                                                        .WithInjectionParameters(new KeyValuePair <string, object>("modelValidatorProviders", config.Services.GetServices(typeof(ModelValidatorProvider))
                                                                                                                                                   .Where(provider => !(provider is DataAnnotationsModelValidatorProvider))
                                                                                                                                                   .Cast <ModelValidatorProvider>())));

            config.Services.Clear(typeof(ModelValidatorProvider));

            return(container);
        }
Example #24
0
 internal StashboxContainer(IStashboxContainer parentContainer, IContainerExtensionManager containerExtensionManager,
                            IResolverSelector resolverSelector)
 {
     this.disposed                  = new AtomicBool();
     this.ParentContainer           = parentContainer;
     this.containerExtensionManager = containerExtensionManager;
     this.resolverSelector          = resolverSelector;
     this.registrationRepository    = new RegistrationRepository();
     this.ContainerContext          = new ContainerContext(this.registrationRepository, new DelegateRepository(), this,
                                                           new ResolutionStrategy(this.resolverSelector), parentContainer.ContainerContext.ContainerConfigurator,
                                                           parentContainer.ContainerContext.DecoratorRepository);
     this.activationContext = new Resolution.ActivationContext(this.ContainerContext, this.resolverSelector, this);
     this.containerExtensionManager.ReinitalizeExtensions(this.ContainerContext);
     this.expressionBuilder     = new ExpressionBuilder(this.ContainerContext, this.containerExtensionManager);
     this.objectBuilderSelector = new ObjectBuilderSelector(this.ContainerContext, this.expressionBuilder);
     this.ServiceRegistrator    = new ServiceRegistrator(this.ContainerContext, this.containerExtensionManager, this.objectBuilderSelector);
 }
Example #25
0
        public static HttpApplication AddStashbox(
            this HttpApplication application,
            [NotNull] IStashboxWebFormsConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            lock (Lock)
            {
                AttachEvents(application);

                configuration.Validate();

                RootContainer = SetServiceProvider(configuration).RootContainer;

                return(application);
            }
        }
Example #26
0
        private static void RegisterServices(IStashboxContainer container)
        {
            container.RegisterType<LinkManager>();

            container.RegisterType<HomeController>();

            container.RegisterType<IAuthorizationManager, AuthorizationManager>();

            container.PrepareType<IProfileConfiguration, ProfileConfiguration>()
                     .WithFactory(() => new ProfileConfiguration())
                     .WithLifetime(new SingletonLifetime())
                     .Register();

            //var userManager = new UserManager<IAuthorizationManager, IProfileConfiguration>();

            //container.BuildUp<UserManager<IAuthorizationManager, IProfileConfiguration>>(userManager);

            container.RegisterType<IUserManager, UserManager<IAuthorizationManager, IProfileConfiguration>>();

            container.PrepareType<IControllerFactory, StashboxControllerFactory>()
                     .WithFactory(() => new StashboxControllerFactory(container))
                     .WithLifetime(new SingletonLifetime())
                     .Register();
        }
 public void Init()
 {
     this.container = new StashboxContainer();
     this.container.RegisterExtension(new DecoratorExtension());
 }
Example #28
0
 public override void PrepareBasic()
 {
     this.container = new StashboxContainer();
     this.RegisterBasic();
 }
Example #29
0
 public StashboxChildContainerAdapter(IStashboxContainer container)
 {
     this.childContainer = container.CreateChildContainer();
 }
Example #30
0
 public static void Bootstrap()
 {
     _container = ConfigureContainer();
 }
Example #31
0
 /// <summary>
 /// Sets the default service provider to <see cref="IStashboxContainer"/>.
 /// </summary>
 /// <param name="builder">The <see cref="IWebHostBuilder"/> instance.</param>
 /// <param name="container">An already configured <see cref="IStashboxContainer"/> instance to use.</param>
 /// <returns>The modified <see cref="IWebHostBuilder"/> instance.</returns>
 public static IWebHostBuilder UseStashbox(this IWebHostBuilder builder, IStashboxContainer container) =>
 builder.ConfigureServices(collection => collection.AddStashbox(container));
 /// <summary>
 /// Sets the <see cref="StashboxContainer"/> as the default dependency resolver and sets custom <see cref="IFilterProvider"/> and <see cref="ModelValidatorProvider"/>.
 /// </summary>
 public static void RegisterStashbox(IStashboxContainer container)
 {
     DependencyResolver.SetResolver(new StashboxDependencyResolver(new StashboxPerRequestScopeProvider(container)));
     RegisterComponents(container);
     RemoveDefaultProviders();
 }
 public StashboxDependencyResolver(IStashboxContainer container)
 {
     Container = container;
 }
 public void Compose(IStashboxContainer container)
 {
     container.Register <ITest1, Test11>();
     container.Register <ITest2, Test12>();
 }
Example #35
0
 /// <summary>
 /// Constructor with container provided
 /// </summary>
 /// <param name="container"></param>
 public StashboxLocatorRegistryFactory(IStashboxContainer container) => _container = container;
 public StashboxChildContainerAdapter(IStashboxContainer container)
 {
     this.childContainer = container.CreateChildContainer();
 }
 public StashboxControllerFactory(IStashboxContainer container)
 {
     _container = container;
 }
Example #38
0
 /// <summary>
 /// Sets the default service provider to <see cref="IStashboxContainer"/>.
 /// </summary>
 /// <param name="builder">The <see cref="IHostBuilder"/> instance.</param>
 /// <param name="container">An already configured <see cref="IStashboxContainer"/> instance to use.</param>
 /// <returns>The modified <see cref="IHostBuilder"/> instance.</returns>
 public static IHostBuilder UseStashbox(this IHostBuilder builder, IStashboxContainer container) =>
 builder.UseServiceProviderFactory(new StashboxServiceProviderFactory(container));