Exemplo n.º 1
0
        public static void Configure(IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton <IComputerVisionClient, ComputerVisionClient>(provider =>
            {
                var key         = configuration.GetSection(ComputerVision)["Key"];
                var credentials = new ApiKeyServiceClientCredentials(key);
                return(new ComputerVisionClient(credentials)
                {
                    Endpoint = configuration.GetSection(ComputerVision)["Endpoint"]
                });
            });

            services.AddSingleton <IFaceClient, FaceClient>(provider =>
            {
                var key         = configuration.GetSection(Face)["Key"];
                var credentials = new ApiKeyServiceClientCredentials(key);
                return(new FaceClient(credentials)
                {
                    Endpoint = configuration.GetSection(Face)["Endpoint"]
                });
            });

            services.AddTransient <IOrderResolver <IEnricher>, OrderResolver <IEnricher> >();

            services.AddTransient(typeof(IRepository <>), typeof(Repository <>));

            services.AddTransient <IFaceService, FaceService>();

            services.AddTransient <IPhotoProcessor, PhotoProcessor>();
            services.AddTransient <IPhotoService, PhotoService>();
            services.AddTransient <ISyncService, SyncService>();

            services.AddTransient <IEnricher, MetadataEnricher>();
            services.AddTransient <IEnricher, ThumbnailEnricher>();
            services.AddTransient <IEnricher, PreviewEnricher>();
            services.AddTransient <IEnricher, AnalyzeEnricher>();
            services.AddTransient <IEnricher, ColorEnricher>();
            services.AddTransient <IEnricher, CaptionEnricher>();
            services.AddTransient <IEnricher, TagEnricher>();
            services.AddTransient <IEnricher, CaptionEnricher>();
            services.AddTransient <IEnricher, ObjectPropertyEnricher>();
            services.AddTransient <IEnricher, AdultEnricher>();
            services.AddTransient <IEnricher, FaceEnricher>();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure Database Context
            services.AddDbContext <DatabaseContext>(options => {
                options.UseLazyLoadingProxies().UseSqlServer(Configuration.GetConnectionString("DATABASE_CONNECTION_STRING"));
            });

            // Configure Azure Blob Storage
            BlobServiceClient blobServiceClient =
                new BlobServiceClient(Configuration.GetConnectionString("STORAGE_CONNECTION_STRING"));
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("trees");

            if (!containerClient.Exists())
            {
                containerClient.Create();
                containerClient.SetAccessPolicy(PublicAccessType.Blob);
            }

            services.AddSingleton <BlobServiceClient>(blobServiceClient);

            // Configure Azure Content Moderator
            string contentModeratorKey      = Configuration["CONTENT_MODERATOR_KEY"];
            string contentModeratorEndpoint = Configuration["CONTENT_MODERATOR_ENDPOINT"];

            ServiceClientCredentials contentModeratorCredentials =
                new Microsoft.Azure.CognitiveServices.ContentModerator.ApiKeyServiceClientCredentials(contentModeratorKey);

            ContentModeratorClient contentModeratorClient =
                new ContentModeratorClient(contentModeratorCredentials);

            contentModeratorClient.Endpoint = contentModeratorEndpoint;

            services.AddSingleton <ContentModeratorClient>(contentModeratorClient);

            // Configure Computer Vision for Image Recognition
            string computerVisionKey      = Configuration["COMPUTER_VISION_KEY"];
            string computerVisionEndpoint = Configuration["COMPUTER_VISION_ENDPOINT"];

            ServiceClientCredentials computerVisionCredentials =
                new Microsoft.Azure.CognitiveServices.Vision.ComputerVision.ApiKeyServiceClientCredentials(computerVisionKey);

            ComputerVisionClient computerVisionClient =
                new ComputerVisionClient(computerVisionCredentials);

            computerVisionClient.Endpoint = computerVisionEndpoint;

            services.AddSingleton <ComputerVisionClient>(computerVisionClient);

            // Configure Azure Maps client
            AzureMapsServices mapsClient = new AzureMapsServices(Configuration["MAPS_KEY"]);

            services.AddSingleton <AzureMapsServices>(mapsClient);

            // Add authentication
            services.AddAuthentication(options =>
            {
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultSignInScheme       = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddJwtBearer(options =>
            {
                options.SaveToken = true;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["JWT_ISSUER"],
                    ValidAudience    = Configuration["JWT_AUDIENCE"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT_SIGN_KEY"]))
                };
            })
            .AddFacebook(options =>
            {
                options.ClientId     = Configuration["FACEBOOK_APP_ID"];
                options.ClientSecret = Configuration["FACEBOOK_APP_SECRET"];
                options.SaveTokens   = true;
            });

            // Add controllers
            services.AddControllers();
        }