示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddMvc(options => {
                options.UseHalFormatter();
            });

            var deviceAuthOptions = _configuration.GetDeviceOptions();

            services.AddAuthorization(options =>
            {
                options.AddPolicy(
                    "RequireAuthenticatedUser",
                    policyBuilder => {
                    policyBuilder.RequireAuthenticatedUser();
                });
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddDeviceTokenAuth(deviceAuthOptions);

            services.AddMvc(options => {
                options.Filters.Add(new AuthorizeFilter("RequireAuthenticatedUser"));
            });

            // Configure NetFusion Application Container
            AppContainerSetup.Bootstrap(_configuration, _loggerFactory, services);

            // Return instance of dependency container to be used
            return(new AutofacServiceProvider(AppContainer.Instance.Services));
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddMvc(options => {
                options.UseHalFormatter();
            });

            // Configure NetFusion Application Container
            AppContainerSetup.Bootstrap(_configuration, _loggerFactory, services);

            // Return instance of dependency container to be used
            return(new AutofacServiceProvider(AppContainer.Instance.Services));
        }