﻿using System.Web.Http;
using Autofac;
using Autofac.Integration.WebApi;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(Diacheck.Web.Startup))]

namespace Diacheck.Web
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var containerBuilder = new ContainerBuilder();
            IocConfig.RegisterDependencies(containerBuilder);
            var container = containerBuilder.Build();

//            ConfigureAuth(app, container);

            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            app.Map(new PathString("/api"), builder =>
            {
                var configuration = new HttpConfiguration
                {
                    DependencyResolver = new AutofacWebApiDependencyResolver(container)
                };

                SwaggerConfig.Register(configuration);
                WebApiConfig.Register(configuration);

                builder.UseAutofacWebApi(configuration);
                builder.UseWebApi(configuration);

                configuration.EnsureInitialized();
            });
        }
    }
}
