Exemple #1
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();
            var mobileConfig         = new MobileAppConfiguration();

            mobileConfig
            .UseDefaultConfiguration()
            .ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new MobileServiceInitializer());

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey     = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers   = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler   = config.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(config);
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            //var container = new UnityContainer();
            //container.RegisterType<DbContext, EShopeMobileServiceContext>(new HierarchicalLifetimeManager());
            //container.RegisterType<IRepository<Order>, EFRepository<Order>>(new HierarchicalLifetimeManager());

            HttpConfiguration config = new HttpConfiguration();
            //config.DependencyResolver = new UnityResolver(container);
            //config.Formatters.JsonFormatter.SupportedMediaTypes
            //config.EnableSystemDiagnosticsTracing();

            //config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional });

            //config.Routes.MapHttpRoute(
            //name: "ActionApi",
            //routeTemplate: "api/{controller}/{action}/{id}",
            //defaults: new { id = RouteParameter.Optional });

            //config.Services
            //app.Use
            // Swagger
            //SwaggerConfig.Register(config);

            var mobileAppConfiguration = new MobileAppConfiguration();

            mobileAppConfiguration.UseDefaultConfiguration();
            //.AddMobileAppHomeController()             // from the Home package
            //.MapApiControllers()
            //.AddTables(                               // from the Tables package
            //    new MobileAppTableConfiguration()
            //        .MapTableControllers()
            //        .AddEntityFramework()             // from the Entity package
            //    )
            ////.AddPushNotifications()                   // from the Notifications package
            //.MapLegacyCrossDomainController()         // from the CrossDomain package

            //.AddTablesWithEntityFramework()
            //mobileAppConfiguration.MapApiControllers();
            mobileAppConfiguration.ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            //Database.SetInitializer(new MobileServiceInitializer());

            //var migrator = new DbMigrator(new Migrations.Configuration());
            //migrator.Update();

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey     = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers   = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler   = config.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(config);
            SwaggerConfig.Register(config);
        }