public static void AddCloudy(this IServiceCollection services, Action <CloudyConfigurator> cloudy)
        {
            services.Configure <RouteOptions>(options =>
            {
                options.ConstraintMap.Add("contentroute", typeof(ContentRouteConstraint));
            });

            var options      = new CloudyOptions();
            var configurator = new CloudyConfigurator(services, options);

            cloudy(configurator);

            configurator.AddComponent <CloudyAssemblyHandle>();

            if (Assembly.GetCallingAssembly() != Assembly.GetExecutingAssembly())
            {
                configurator.AddComponentAssembly(Assembly.GetCallingAssembly());
            }

            var AssemblyProvider = new AssemblyProvider(options.Assemblies.Select(a => new AssemblyWrapper(a)));

            services.AddSingleton <IAssemblyProvider>(AssemblyProvider);


            services.AddSingleton <IContextDescriptorProvider>(new ContextDescriptorProvider(ContextDescriptor.CreateFrom(options.Contexts)));

            foreach (var injector in new DependencyInjectorProvider(new DependencyInjectorCreator(AssemblyProvider)).GetAll())
            {
                injector.InjectDependencies(services);
            }

            services.AddTransient <IStartupFilter, InitializerBootstrapper>();
        }
Example #2
0
        public static void AddCloudy(this IServiceCollection services, Action <CloudyConfigurator> configure)
        {
            services.Configure <RouteOptions>(options =>
            {
                options.ConstraintMap.Add("contentroute", typeof(ContentRouteConstraint));
            });

            var options      = new CloudyOptions();
            var configurator = new CloudyConfigurator(services, options);

            configure(configurator);

            configurator.AddComponent <CloudyComponent>();

            if (Assembly.GetCallingAssembly() != Assembly.GetExecutingAssembly())
            {
                configurator.AddComponentAssembly(Assembly.GetCallingAssembly());
            }

            if (!options.HasDocumentProvider)
            {
                configurator.WithInMemoryDatabase();
            }

            var componentAssemblyProvider = new ComponentAssemblyProvider(options.ComponentAssemblies);

            services.AddSingleton <IComponentAssemblyProvider>(componentAssemblyProvider);

            var componentTypeProvider = new ComponentTypeProvider(options.Components);

            services.AddSingleton <IComponentTypeProvider>(componentTypeProvider);

            new CloudyDependencyInjector().InjectDependencies(services);

            foreach (var injector in new DependencyInjectorProvider(new DependencyInjectorCreator(componentAssemblyProvider, componentTypeProvider)).GetAll())
            {
                injector.InjectDependencies(services);
            }

            services.AddTransient <IStartupFilter, InitializerBootstrapper>();
        }