Beispiel #1
0
 /// <summary>
 /// Return the default implementation for an specific service.
 /// </summary>
 /// <typeparam name="T">Type of service.</typeparam>
 /// <returns>Object implementation registered on IoC container.</returns>
 public T Resolve <T>()
 {
     if (appContainer == null)
     {
         appContainer = ContainerManager.BuildContainer();
     }
     return(appContainer.Resolve <T>());
 }
Beispiel #2
0
        /// <summary>
        /// Called before all resources are loaded on AppDomain. This is done so we can guarantee
        /// that all code, including Framework code, is running using Database registered assembly Version.
        /// </summary>
        void IApplication.RunInception()
        {
            if (appContainer == null)
            {
                appContainer = ContainerManager.BuildContainer();
            }
            var boot = appContainer.Resolve <Boot>();

            boot.StartUp();
        }
Beispiel #3
0
        /// <summary>
        /// Start point for Dover Addon.
        /// </summary>
        public void Run()
        {
            if (appContainer == null)
            {
                appContainer = ContainerManager.BuildContainer();
            }
            var microCore = appContainer.Resolve <MicroCore>();

            microCore.PrepareFramework();
        }
Beispiel #4
0
        /// <summary>
        /// Called before all resources are loaded on AppDomain. This is done so we can guarantee
        /// that all code, including Framework code, is running using Database registered assembly Version.
        /// </summary>
        internal void RunInception()
        {
            if (appContainer == null)
            {
                appContainer = ContainerManager.BuildContainer();
            }
            var boot = appContainer.Resolve <Boot>();

            boot.StartUp();
            appContainer.Dispose();
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // Register AutoFac
            var container = ContainerManager.BuildContainer();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Beispiel #6
0
        /// <summary>
        /// Called for each addin that is started by Dover.
        /// </summary>
        internal void RunAddin()
        {
            if (appContainer == null)
            {
                appContainer = ContainerManager.BuildContainer();
            }
            var loader = appContainer.Resolve <Boot>();

            if (loader.StartThis()) // in case of error, stop addin but do not close Dover.
            {
                ManualResetEvent           shutdownEvent        = (ManualResetEvent)AppDomain.CurrentDomain.GetData("shutdownEvent");
                Sponsor <ManualResetEvent> shutdownEventSponsor = new Sponsor <ManualResetEvent>(shutdownEvent);
                shutdownEvent.WaitOne(); // Wait until shutdown event is signaled.
            }
        }
Beispiel #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var config = new MapperConfiguration(cfg => { cfg.AddProfile(new WebMappingsProfileConfiguration()); });
            var mapper = config.CreateMapper();

            services.AddSingleton(mapper);
            services.AddMvc();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Advanced Studio Exercise API", Version = "v1"
                });
            });

            services.Configure <AppConnectionStrings>(Configuration.GetSection("ConnectionStrings"));

            return(new AutofacServiceProvider(ContainerManager.BuildContainer(services)));
        }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("Lab3DBAuth")));

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

            services.AddCors();

            services.AddMvc().AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddDbContext <DBContext>();

            services.AddAutofac();

            services.AddSingleton <IJwtFactory, JwtFactory>();

            var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtIssuerOptions));

            // Configure JwtIssuerOptions
            services.Configure <JwtIssuerOptions>(options =>
            {
                options.Issuer             = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)];
                options.Audience           = jwtAppSettingOptions[nameof(JwtIssuerOptions.Audience)];
                options.SigningCredentials = new SigningCredentials(_signingKey, SecurityAlgorithms.HmacSha256);
            });

            var tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer = true,
                ValidIssuer    = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)],

                ValidateAudience = true,
                ValidAudience    = jwtAppSettingOptions[nameof(JwtIssuerOptions.Audience)],

                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = _signingKey,

                RequireExpirationTime = false,
                ValidateLifetime      = true,
                ClockSkew             = TimeSpan.Zero
            };

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(configureOptions =>
            {
                configureOptions.ClaimsIssuer = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)];
                configureOptions.TokenValidationParameters = tokenValidationParameters;
                configureOptions.SaveToken = true;
            });

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingProfile());
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            return(new AutofacServiceProvider(ContainerManager.BuildContainer(services)));
        }