コード例 #1
0
        void AddItems(WixEntity[] items)
        {
            Shortcuts         = items.OfType <FileShortcut>().ToArray();
            Associations      = items.OfType <FileAssociation>().ToArray();
            IISVirtualDirs    = items.OfType <IISVirtualDir>().ToArray();
            ServiceInstallers = items.OfType <ServiceInstaller>().Cast <IGenericEntity>().ToArray();
            Permissions       = items.OfType <FilePermission>().ToArray();
            AppIds            = items.OfType <AppId>().ToArray();
            GenericItems      = items.OfType <IGenericEntity>().Where(val => val.GetType() != typeof(ServiceInstaller)).ToArray();

            FirewallExceptions = items.OfType <FirewallException>().ToArray();

            var firstUnExpectedItem = items.Except(Shortcuts)
                                      .Except(Associations)
                                      .Except(IISVirtualDirs)
                                      .Except(Permissions)
                                      .Except(FirewallExceptions)
                                      .Except(AppIds)
                                      .Except(GenericItems.Cast <WixEntity>())
                                      .Where(x => !(x is IGenericEntity) || !ServiceInstallers.Contains(x as IGenericEntity))
                                      .ToArray();

            if (firstUnExpectedItem.Any())
            {
                throw new ApplicationException("{0} is unexpected. Only {2}, {3}, {4}, {5}, {6}, {7}, and {8} items can be added to {1}".FormatWith(
                                                   firstUnExpectedItem.First().GetType(),
                                                   this.GetType(),
                                                   typeof(FileShortcut),
                                                   typeof(FileAssociation),
                                                   typeof(ServiceInstaller),
                                                   typeof(FilePermission),
                                                   typeof(FirewallException),
                                                   typeof(AppId),
                                                   typeof(IGenericEntity)));
            }
        }
コード例 #2
0
 public static void Configure(IServiceCollection services, IConfiguration configuration)
 {
     ContextInstaller.Configure(services, configuration);
     RepositoryInstallers.Configure(services);
     ServiceInstallers.Configure(services);
 }
コード例 #3
0
ファイル: Startup.cs プロジェクト: mwellborn/sample-webapi
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // Configure strongly typed settings
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));

            var appSettingsSection = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);

            // Configure Json Web Token Authentication
            var appSettings = appSettingsSection.Get <AppSettings>();
            var key         = Encoding.ASCII.GetBytes(appSettings.JwtSecret);

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            // Configure Dependency Injection
            InfrastructureInstallers.Install(services);
            RepositoryInstallers.Install(services);
            ServiceInstallers.Install(services);

            // Configure Swagger
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info {
                    Title = "Sample Web Api", Version = "v1"
                });
                options.AddSecurityDefinition("Bearer", new ApiKeyScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = "header",
                    Type        = "apiKey"
                });
                options.AddSecurityRequirement(
                    new Dictionary <string, IEnumerable <string> >
                {
                    {
                        "Bearer",
                        new string[] { }
                    },
                });
            });
        }