Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            AutomapperConfig.Initialize();
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <LibraryContext>(options =>
                                                   options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            // services.AddAutoMapper(); // we need this when we register maps via AutoMapper.Profile
            AutomapperConfig.Initialize();
            OrderMapperConfig.Initialize();

            services.AddMvc(options =>
            {
                options.Filters.Add <ExceptionFilter>();
                options.ReturnHttpNotAcceptable = true;
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssembly(GetType().Assembly));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Rest API Learn", Version = "v1"
                });
            });

            services.AddSingleton(Mapper.Instance);
            services.AddScoped <ILibraryRepository, LibraryRepository>();
        }
Ejemplo n.º 3
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     AutomapperConfig.Initialize();
 }
Ejemplo n.º 4
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterModule <RepositoryModule>();
            builder.RegisterModule <ServiceModule>();
            builder.RegisterModule <CommandModule>();

            builder.RegisterInstance(AutomapperConfig.Initialize()).SingleInstance();
        }
Ejemplo n.º 5
0
        protected void Application_Start()
        {
            var container = new Container();

            SimpleInjectorConfig.Initialize(container);
            GlobalConfiguration.Configure(WebApiConfig.Register);
            AutomapperConfig.Initialize();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Ejemplo n.º 6
0
        protected void Application_Start()
        {
            AutomapperConfig.Initialize();
            AutofacBootstrapper.Run();

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterInstance(AutomapperConfig.Initialize())
     .SingleInstance();
     builder.RegisterModule <CommandModule>();
     builder.RegisterModule <QueryModule>();
     builder.RegisterModule <CqrsMediatorModule>();
     builder.RegisterModule <RepositoryModule>();
     builder.RegisterModule <SqlModule>();
     builder.RegisterModule <MongoModule>();
     builder.RegisterModule <ServiceModule>();
     builder.RegisterModule(new SettingsModule(_configuration));
     builder.RegisterModule <WorkloadModule>();
 }
Ejemplo n.º 8
0
        public static void Register(HttpConfiguration config)
        {
            var container = IoC.Initialize();

            config.MapHttpAttributeRoutes();

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

            AutomapperConfig.Initialize(container);
        }
Ejemplo n.º 9
0
        public void Configuration(IAppBuilder app)
        {
            AreaRegistration.RegisterAllAreas();

            AutomapperConfig.Initialize();
            AutofacBootstrapper.Run();

            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            ConfigureAuth(app);
        }
Ejemplo n.º 10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            this.RegisterAppInfo();

            // Dependency injection.
            services.AddSingleton <IDbFactory, DbFactory>();

            services.AddScoped <ICategoryService, CategoryService>();
            services.AddScoped <ICommentService, CommentService>();
            services.AddScoped <IArticleService, ArticleService>();
            services.AddScoped <IUserService, UserService>();
            services.AddScoped <IRoleService, RoleService>();
            services.AddScoped <IUserRoleService, UserRoleService>();

            services.AddScoped <ICategoryRepository, CategoryRepository>();
            services.AddScoped <ICommentRepository, CommentRepository>();
            services.AddScoped <IArticleRepository, ArticleRepository>();
            services.AddScoped <IRoleRepository, RoleRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserRoleRepository, UserRoleRepository>();

            // Automapper config
            AutomapperConfig.Initialize();

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddMvc().AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizePage("/test1", "OnlyAdminAccess");
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddAuthorization(options =>
            {
                options.AddPolicy("OnlyAdminAccess", policy => policy.RequireRole("Admin"));
            });
        }
Ejemplo n.º 11
0
        public static void Initialize(TestContext test)
        {
            // Automapper
            var config = new AutomapperConfig();

            config.Initialize();

            //// Common
            //var dbStub = new HatchlingCompanyDbContext(Effort.DbConnectionFactory.CreateTransient());
            //var writerStub = new Mock<IWriter>();
            //var mapperStub = new Mock<IMapper>();

            //// Services
            //var createEmployeeService = new CreateEmployee(dbStub, writerStub.Object, mapperStub.Object);
        }
Ejemplo n.º 12
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            AutomapperConfig.Initialize();

            // Remove data annotations validation provider
            ModelValidatorProviders.Providers.Remove(
                ModelValidatorProviders.Providers.OfType <DataAnnotationsModelValidatorProvider>().First());

            DependencyInjection();
        }
Ejemplo n.º 13
0
        public static void Main()
        {
            var strategy = new MigrateDatabaseToLatestVersion <HatchlingCompanyDbContext, Configuration>();

            Database.SetInitializer(strategy);

            var config = new AutomapperConfig();

            config.Initialize();

            var builder = new ContainerBuilder();

            builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly());

            var container = builder.Build();

            var engine = container.Resolve <IEngine>();

            engine.Start();
        }
Ejemplo n.º 14
0
 public AutomapperTest()
 {
     Mapper.Reset();
     AutomapperConfig.Initialize();
 }
Ejemplo n.º 15
0
 protected void Application_Start()
 {
     AutomapperConfig.Initialize();
     IocConfig.Configure();
     GlobalConfiguration.Configure(WebApiConfig.Register);
 }
 public static void InitilizeAutomapper(TestContext context)
 {
     AutomapperConfig.Reset();
     AutomapperConfig.Initialize();
 }
Ejemplo n.º 17
0
        // This method gets called by the runtime. Use this method to add services to the Description.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services
            .AddSwaggerGen(opt =>
            {
                opt.SwaggerDoc(
                    Configuration["Api:Name"],
                    new Info
                {
                    Title       = Configuration["Api:Title"],
                    Version     = Configuration["Api:Version"],
                    Description = Configuration["Api:Description"]
                });

                opt.AddSecurityDefinition(
                    "Bearer",
                    new ApiKeyScheme
                {
                    In = "header", Description = "Please enter JWT with Bearer into field", Name = "Authorization", Type = "apiKey"
                });

                opt.AddSecurityRequirement(
                    new Dictionary <string, IEnumerable <string> >
                {
                    { "Bearer", Enumerable.Empty <string>() },
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                opt.IncludeXmlComments(xmlPath);
            })
            .AddMvc(opt =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                opt.Filters.Add(new AuthorizeFilter(policy));
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services
            .AddSingleton(AutomapperConfig.Initialize())
            .AddDbContext <ApplicationDbContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")))
            .AddAuthentication(opt =>
            {
                opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                opt.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                opt.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(opt =>
            {
                opt.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Jwt:Issuer"],
                    ValidAudience    = Configuration["Jwt:Audience"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])),
                };
            });

            var builder = new ContainerBuilder();

            AutofacConfig.Register(builder);
            builder.Populate(services);
            builder.RegisterModule(new SettingsModule(Configuration));
            builder.RegisterModule <CommandModule>();
            AutofacContainer = builder.Build();

            return(new AutofacServiceProvider(AutofacContainer));
        }