Beispiel #1
0
 public static IIocResolve Resolve(IIocConfig config)
 {
     if (_resolve == null)
     {
         _resolve = new IocResolve(config);
     }
     return(_resolve);
 }
Beispiel #2
0
 public static IIocResolve Resolve(IIocConfig config)
 {
     if (_resolve == null)
     {
         _resolve = new IocResolve(config);
     }
     return _resolve;
 }
Beispiel #3
0
 public IocResolve(IIocConfig config)
 {
     _config = config;
 }
Beispiel #4
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add Glimpse
            // services.AddGlimpse();

            // Add framework services.
            // services.AddApplicationInsightsTelemetry(Configuration);

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("PilotKit")));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddMvc();

            // Add application services.
            services.AddTransient <IEmailSender, AuthMessageSender>();
            services.AddTransient <ISmsSender, AuthMessageSender>();

            // only allow authenticated users
            var defaultPolicy = new AuthorizationPolicyBuilder()
                                .RequireAuthenticatedUser()
                                .Build();

            services.AddMvc(setup =>
            {
                setup.Filters.Add(new AuthorizeFilter(defaultPolicy));
            });

            // Add MVC services to the services container.
            //services.AddMvc();
            //services.AddMvc().AddJsonOptions(options =>
            //{
            //    options.SerializerSettings.ContractResolver =
            //        new CamelCasePropertyNamesContractResolver();
            //});

            // Add Application settings to the services container.
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
            services.AddTransient <IIocConfig, IocConfig>();

            // Create a provider from the service collection
            IServiceProvider provider = services.BuildServiceProvider();

            // Instantiate Autofac ModuleLoading class
            this.AutofacConfig = provider.GetService <IIocConfig>();

            //ConfigManager.AppSettings = ;
            //ConfigManager.ConnectionStrings = ;

            // Create the container builder.
            var builder = new ContainerBuilder();

            this.AutofacConfig.RegisterDependencies(builder);

            // Register dependencies, populate the services from
            // the collection, and build the container.
            // builder.RegisterType<MyType>().As<IMyType>();
            builder.Populate(services);
            Container = builder.Build();

            // Return the IServiceProvider resolved from the container.
            return(Container.Resolve <IServiceProvider>());
        }