Ejemplo n.º 1
0
        public static IAppBuilder UseCredentialRepository(this IAppBuilder app, string controllerPrefix, ICredentialRepositoryOptions options)
        {
            return(app.Map(
                       controllerPrefix,
                       builder =>
            {
                var config = new HttpConfiguration();

                // Set up DI
                var containerBuilder = new ContainerBuilder();

                containerBuilder.RegisterInstance(options).AsImplementedInterfaces();

                Database.SetInitializer(options.DatabaseInitializer);
                var encryptionOptions = new EncryptionServiceOptions(options.CertificateThumbprint, options.StoreName, options.StoreLocation);
                containerBuilder.Register(c => new CredentialRepositoryContext(options.NameOrConnectionString, new EncryptionService(encryptionOptions)))
                .As <DbContext>()
                .As <CredentialRepositoryContext>();

                var container = ConfigureDependencyInjection(config, containerBuilder);
                builder.UseAutofacMiddleware(container);
                builder.UseAutofacWebApi(config);

                // Set up filters
                config.Filters.Add(new AuthorizeAttribute());
                config.MessageHandlers.Add(new AuthenticationHandler(container));

                // Map routes and formatting
                config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
                config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

                config.IncludeErrorDetailPolicy = options.IncludeErrorDetailPolicy;

                config.MapHttpAttributeRoutes();
                builder.UseWebApi(config);
            }));
        }
Ejemplo n.º 2
0
 public static IAppBuilder UseCredentialRepository(this IAppBuilder app, ICredentialRepositoryOptions options)
 {
     return(UseCredentialRepository(app, "/api/v2/credentials", options));
 }