public static void RegisterServices(this Container container) { UnitOfWorkModule.Register(container); ServicesModule.Register(container); RepositoryModule.Register(container); DbContextModule.Register(container); }
/// <inheritdoc /> /// <summary> /// Register's the application module /// </summary> /// <param name="container">The reference to the DryIOC container</param> public void Register(IContainer container) { var configuration = Startup.Configuration; CommonWebApiModules.Register(container, configuration); ServicesModule.Register(container); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "My API", Description = "My ASP.NET Core Web API Demo", TermsOfService = "None", Contact = new Contact { Name = "Benjamin Bagley", Email = "*****@*****.**" } }); }); PersistenceModule.Configure(services); ServicesModule.Configure(services); Mapper.Initialize(x => { x.AddProfile(new WebMappingProfile()); x.AddProfile(new PersistenceMappingProfile()); }); }
public void ShouldAddNotificationViewToNotificationsRegion() { var toolsRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityContainer(); var configurationService = new MockConfigurationService(); container.Bag.Add(typeof(INotificationViewPresenter), new MockNotificationViewPresenter()); container.Bag.Add(typeof(IProjectService), new MockProjectService()); container.Bag.Add(typeof(ICacheManager), new MockCacheManager()); container.Bag.Add(typeof(IConfigurationService), configurationService); toolsRegion.Name = RegionNames.NotificationsRegion; regionManager.Regions.Add(toolsRegion); configurationService.GetParameterValueReturnFunction = p => "polling"; var module = new ServicesModule(container, regionManager); Assert.AreEqual(0, toolsRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, toolsRegion.AddedViews.Count); Assert.IsInstanceOfType(toolsRegion.AddedViews[0], typeof(INotificationView)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IDataSeed>(new DataSeed()); RepositoryModule.Register(services, Configuration.GetConnectionString("DefaultConnection"), GetType().Assembly.FullName); ServicesModule.Register(services); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "CrossOver API Documentation", Version = "v1", Description = "This API makes use of json response", Contact = new Contact() { Email = "*****@*****.**", Name = "Emad Hamdy" } }); //c.AddSecurityDefinition("Bearer", new ApiKeyScheme() { In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey" }); //c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>> // { // { "Bearer", new string[]{ } }, // { "Basic", new string[]{ } }, // }); // Set the comments path for the Swagger JSON and UI. var basePath = PlatformServices.Default.Application.ApplicationBasePath; var xmlPath = Path.Combine(basePath, "XOProject.Api.xml"); c.IncludeXmlComments(xmlPath); }); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { RepositoryModule.Register(services, Configuration.GetConnectionString("DefaultConnection"), GetType().Assembly.FullName); ServicesModule.Register(services); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { RepositoryModule.Register(services, Configuration.GetConnectionString("DefaultConnection"), GetType().Assembly.FullName); ServicesModule.Register(services); services.AddMvc(option => option.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); //services.AddControllers(); }
public App() { InitializeComponent(); ServicesModule.Load(); MainPage = new MainPage(); }
public static void LoadModules(IServiceCollection services, IConfiguration configuration) { ApplicationInsightsModule.Load(services, configuration); FactoriesModule.Load(services); ServicesModule.Load(services); RepositoriesModule.Load(services, configuration); CommonModule.Load(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IDataSeed>(new DataSeed()); RepositoryModule.Register(services, Configuration.GetConnectionString("DefaultConnection"), GetType().Assembly.FullName); ServicesModule.Register(services); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddAutoMapper(); DAModule.ConfigureServices(services, Configuration); ServicesModule.ConfigureServices(services, Configuration); AggregationModule.ConfigureDrivers(services, Configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { RepositoryModule.Register(services, Configuration.GetConnectionString("DefaultConnection"), GetType().Assembly.FullName); ServicesModule.Register(services); services.AddMvc(option => option.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddCors(allowsites => { allowsites.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin()); }); }
private void DependencyInjection() { // dependency injection NinjectModule dependencesModule = new DependencesModule(); NinjectModule serviceModule = new ServicesModule("HIMSDbContext", "HimsIdentityConnection"); var kernel = new StandardKernel(dependencesModule, serviceModule); DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger(); services.Configure <FormOptions>(options => { options.ValueLengthLimit = int.MaxValue; options.MultipartBodyLengthLimit = int.MaxValue; options.MemoryBufferThreshold = int.MaxValue; }); services.AddScoped(typeof(IGenericRepository <>), typeof(GenericRepository <>)); //Register services ServicesModule.Register(services); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); // ASP.NET Core DI services.AddScoped <ApplicationContext, ApplicationContext>(); //services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString(SQLSERVER_CONNECTION_STRING_KEY))); services.AddDbContext <ApplicationContext>(options => options.UseInMemoryDatabase(databaseName: "HaunDb")); services.AddControllersWithViews(); services.AddTransient <IUnitOfWork, UnitOfWork>(); //Fluent Validator services.AddControllersWithViews().AddFluentValidation(opt => { opt.RegisterValidatorsFromAssembly(Assembly.GetExecutingAssembly()); }); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = OPEN_API_TITLE, Version = "v1" }); //c.OperationFilter<ExamplesOperationFilter>(); }); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
/// <summary> /// Инициализация контейнера /// </summary> /// <param name="containerBuilderHandler">Делегат для дополнительной инициализации контейнера</param> public static IContainer Init(Action <ContainerBuilder> containerBuilderHandler = null) { if (_builder != null) { return(_container); } _builder = new ContainerBuilder(); containerBuilderHandler?.Invoke(_builder); ServicesModule.InitModules(_builder); _container = _builder.Build(); return(_container); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddOpenApiDocument(); services.AddHttpContextAccessor(); services.TryAddSingleton <IActionContextAccessor, ActionContextAccessor>(); ServicesModule.RegisterServices(services, this.Configuration); IMapper mapper = Services.Mapper.GetMapper(); services.AddSingleton(mapper); }
public void DoA401ClearsHeaders() { //Arrange var response = new Mock <HttpResponseBase>(); var context = new Mock <IServicesContext>(); context.Setup(x => x.DoA401).Returns(true); context.Setup(x => x.BaseContext.Response).Returns(response.Object); //Act ServicesModule.CheckForReal401(context.Object); //Assert response.Verify(x => x.ClearHeaders()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //Внедрение зависимостей NinjectModule DBModule = new DBModule("MyConnection"); NinjectModule servicesModule = new ServicesModule(); var kernel = new StandardKernel(DBModule, servicesModule); System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new Ninject.WebApi.DependencyResolver.NinjectDependencyResolver(kernel); }
public void SupportsDigestAddsDigestHeader() { //Arrange var response = new Mock <HttpResponseBase>(); var context = new Mock <IServicesContext>(); context.Setup(x => x.DoA401).Returns(true); context.Setup(x => x.SupportDigestAuth).Returns(true); context.Setup(x => x.BaseContext.Response).Returns(response.Object); //Act ServicesModule.CheckForReal401(context.Object); //Assert response.Verify(x => x.AppendHeader("WWW-Authenticate", It.IsRegex("^Digest.*", RegexOptions.IgnoreCase))); }
public void DoA401CausesStatusCode401() { //Arrange var response = new Mock <HttpResponseBase>(); response.SetupProperty(x => x.StatusCode); var context = new Mock <IServicesContext>(); context.Setup(x => x.DoA401).Returns(true); context.Setup(x => x.BaseContext.Response).Returns(response.Object); //Act ServicesModule.CheckForReal401(context.Object); //Assert Assert.AreEqual(401, response.Object.StatusCode); }
private void DependencyInjection() { // dependency injection NinjectModule registrations = new NinjectRegistrations(); NinjectModule services = new ServicesModule("HIMSDbContext", "HimsIdentityConnection"); var kernel = new StandardKernel(registrations, services); kernel.Bind<DefaultModelValidatorProviders>().ToConstant(new DefaultModelValidatorProviders(GlobalConfiguration.Configuration.Services.GetModelValidatorProviders())); var ninjectResolver = new Core.NinjectDependencyResolver(kernel); DependencyResolver.SetResolver(ninjectResolver); GlobalConfiguration.Configuration.DependencyResolver = new Core.NinjectDependencyResolver(kernel); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { DomainServicesModule.ConfigureServices(services); ServicesModule.ConfigureServices(services); VMServicesModule.ConfigureServices(services); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { //Адрес страницы аутентификации options.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Auth/Login"); }); services .AddMvc() .AddSessionStateTempDataProvider(); services.AddSession(); }
public void NoDoA401DoesNothing() { //Arrange var response = new Mock <HttpResponseBase>(); var context = new Mock <IServicesContext>(); context.Setup(x => x.DoA401).Returns(false); context.Setup(x => x.BaseContext.Response).Returns(response.Object); //Act ServicesModule.CheckForReal401(context.Object); //Assert response.Verify(x => x.StatusCode, Times.Never()); response.Verify(x => x.ClearContent(), Times.Never()); response.Verify(x => x.AppendHeader(It.IsAny <string>(), It.IsAny <string>()), Times.Never()); response.Verify(x => x.AddHeader(It.IsAny <string>(), It.IsAny <string>()), Times.Never()); response.Verify(x => x.Headers, Times.Never()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddSignalR(); services.Configure <RazorViewEngineOptions>(o => { o.ViewLocationExpanders.Add(new MyViewLocationExpander()); }); services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true }); }); var connections = Configuration.GetSection("ConnectionStrings"); services.AddDbContext <DataContext>(options => options.UseSqlServer(connections["DefaultConnection"])); // IoC ServicesModule.AddServices(services); var serviceProvider = services.BuildServiceProvider(); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { Configuration.GetSection("Auth0").Bind(options); options.Events = GetJwtBearerEvents(serviceProvider); }); Console.WriteLine("Env: " + HostingEnvironment.EnvironmentName); if (!HostingEnvironment.IsDevelopment() && !HostingEnvironment.IsEnvironment("local")) { // services.Configure<MvcOptions>(options => { // options.Filters.Add(new RequireHttpsAttribute()); // }); } }
public void IsStaleSetsStaleNonceIndicator(bool stale) { //Arrange var response = new Mock <HttpResponseBase>(); var context = new Mock <IServicesContext>(); context.Setup(x => x.DoA401).Returns(true); context.Setup(x => x.IsStale).Returns(stale); context.Setup(x => x.SupportBasicAuth).Returns(false); //avoid basic auth header context.Setup(x => x.SupportDigestAuth).Returns(true); context.Setup(x => x.BaseContext.Response).Returns(response.Object); //Act ServicesModule.CheckForReal401(context.Object); //Assert var regex = string.Format("^Digest.*, stale={0}.*", stale); response.Verify(x => x.AppendHeader("WWW-Authenticate", It.IsRegex(regex, RegexOptions.IgnoreCase))); }
public void ShouldAddNotificationViewToNotificationsRegion() { var toolsRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); container.Bag.Add(typeof(INotificationViewPresenter), new MockNotificationViewPresenter()); container.Bag.Add(typeof(IProjectService), new MockProjectService()); toolsRegion.Name = RegionNames.NotificationsRegion; regionManager.Regions.Add(toolsRegion); var module = new ServicesModule(container, regionManager); Assert.AreEqual(0, toolsRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, toolsRegion.AddedViews.Count); Assert.IsInstanceOfType(toolsRegion.AddedViews[0], typeof(INotificationView)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter); //dependencies //TODO connectionString //Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DAL.EduDbContext;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False NinjectModule servicesModule = new ServicesModule(ConfigurationManager.ConnectionStrings["EduDb"].ToString()); NinjectModule serviceModule = new ServiceModule(); var kernel = new StandardKernel(servicesModule, serviceModule); //GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); //DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); }
private void DependencyInjection() { // dependency injection var dependencesModule = new DependencesModule(); var autoMapperServerModule = new AutoMapperModule(); var serviceModule = new ServicesModule("DIMSDBConnection", "DIMSIdentityConnection"); var kernel = new StandardKernel(dependencesModule, serviceModule, autoMapperServerModule); kernel.Bind <DefaultModelValidatorProviders>().ToConstant(new DefaultModelValidatorProviders(GlobalConfiguration.Configuration.Services.GetModelValidatorProviders())); kernel.Bind <DefaultFilterProviders>().ToConstant(new DefaultFilterProviders(GlobalConfiguration.Configuration.Services.GetFilterProviders())); var ninjectResolver = new NinjectDependencyResolver(kernel); DependencyResolver.SetResolver(ninjectResolver); GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); }
protected void Application_Start() { Mapper.Initialize(cfg => cfg.AddProfiles (new[] { typeof(Web.Util.AutoMapperProfile), typeof(UserStore.BLL.Util.AutoMapperProfile), typeof(BLL.Util.AutoMapperProfile) })); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); NinjectModule servicesModule = new ServicesModule(); NinjectModule userModule = new UserModule(); NinjectModule databaseModule = new DatabaseModule(); var kernel = new StandardKernel(servicesModule, userModule, databaseModule); kernel.Unbind <ModelValidatorProvider>(); DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); }
public void ConfigureServices(IServiceCollection services) { RepositoriesModule.RegisterDependencies(services, Configuration); ServicesModule.RegisterDependencies(services); services.AddCors(options => { options.AddPolicy(BudgetPolicy, builder => { builder.WithOrigins("http://localhost:4200") .AllowAnyHeader() .AllowCredentials() .AllowAnyMethod(); }); }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ClockSkew = TimeSpan.Zero, ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Issuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Secret"])) }; }); services.AddHttpContextAccessor(); services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new DateTimeConverter()); }); }