public void ConfigureServices(IServiceCollection services) { //Configure AppSettings section var appConfig = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appConfig); //Using AppSettings var appSettings = appConfig.Get <AppSettings>(); string connectionString = appSettings.CommanderConnectionString; DIModule.Register(services, connectionString); services.AddControllers().AddNewtonsoftJson(s => { s.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); //Mapping to DTO's services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //Registering services //services.AddScoped<ICommanderRepo, CommanderRepo>(); services.AddScoped <ICommanderRepo, SqlCommanderRepo>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var appConfig = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appConfig); var appSettings = appConfig.Get <AppSettings>(); var secret = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(secret), ValidateIssuer = false, ValidateAudience = false }; }); services.AddTransient <IFlowerService, FlowerService>(); services.AddTransient <IOrderService, OrderService>(); services.AddTransient <IUserService, UserService>(); DIModule.RegisterModule(services, appSettings.AppConnectionString); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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; }); DIModule.RegisterModule(services, Configuration.GetConnectionString("BudgetDbConnection")); services.AddAutoMapper(x => x.AddProfile <MapperProfile>()); services.AddMvc().AddNToastNotifyToastr(new ToastrOptions() { ProgressBar = false, PositionClass = ToastPositions.TopRight, CloseButton = true }); services.AddTransient <IIncomeService, IncomeService>(); services.AddTransient <IExpenseService, ExpenseService>(); services.AddTransient <IUserService, UserService>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetConnectionString("DefaultConnection"); DIModule.RegisterModule(services, connectionString); services.AddTransient <IUserService, UserService>(); services.AddTransient <IToDoService, ToDoService>(); //automapper var config = new MapperConfiguration(cfg => cfg.AddProfile(new MapperProfile())); var mapper = config.CreateMapper(); services.AddSingleton(mapper); //token authorisation services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = _localhost, //ValidAudience = _localhost, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("logInSecretKey@123456")) }; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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; }); //Configuring AppSettings section var appConfig = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appConfig); //Using AppSettings section var appSettings = appConfig.Get <AppSettings>(); DIModule.RegisterModule(services, appSettings.LamazonDbConnectionString); services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); //services.AddDbContext<LamazonDbContext>(ob => ob.UseSqlServer( // Configuration.GetConnectionString("LamazonDbConnection") //)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); DIModule.ConfigureClassDI(services); services.AddMediatR(typeof(ProductsCreateCommand).GetTypeInfo().Assembly); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetValue <string>("CompanyAppConnectionString"); DIModule.DIConnecting(services, connectionString); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { DIModule.ConfigureDbConnection(services, Configuration); DIModule.ConfigureClassesDI(services); services.AddControllers(); services.AddSwaggerGen(); }
// 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); // get connection string from app settings json file var connectionString = Configuration.GetConnectionString("DefaultConnection"); DIModule.RegisterModule(services, connectionString); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { hostContext.Configuration = DIModule.ConfigureJson();; services.ConfigureServices(hostContext.Configuration); services.AddScoped <DbConnectionConfigWorker>(); services.AddScoped <ConsoleWorker>(); });
// 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) .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore); var connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddTransient <IUserServices, UserService>(); services.AddTransient <INoteServices, NoteService>(); DIModule.RegisterModule(services, connectionString); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetValue <string>("LamazonConnectionString"); DIModule.RegisterModule(services, connectionString); services.AddTransient <IUserService, UserService>(); services.AddTransient <IOrderService, OrderService>(); services.AddTransient <IProductService, ProductService>(); services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public void baasic_client_infrastructure_dependency_injection_register_test() { this.fixture.Target.Should().NotBeNull(); Action execute = () => { var module = new DIModule(); module.Load(this.fixture.Target); }; execute.ShouldNotThrow(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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; }); //Configuring AppSettings section var appConfig = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appConfig); //Using AppSettings section var appSettings = appConfig.Get <AppSettings>(); DIModule.RegisterModule(services, appSettings.LamazonDbConnectionString); services.ConfigureApplicationCookie(options => { options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(60); options.LoginPath = "/Users/LogIn"; options.AccessDeniedPath = "/Users/LogIn"; options.SlidingExpiration = true; }); services.AddMvc().AddNToastNotifyToastr(new ToastrOptions() { ProgressBar = false, PositionClass = ToastPositions.TopRight, CloseButton = true }); services.AddTransient <IUserService, UserService>(); services.AddTransient <IOrderService, OrderService>(); services.AddTransient <IProductService, ProductService>(); services.AddTransient <IInvoiceService, InvoiceService>(); services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); //services.AddDbContext<LamazonDbContext>(ob => ob.UseSqlServer( // Configuration.GetConnectionString("LamazonDbConnection") //)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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; }); DIModule.RegisterDependencies(services, Configuration.GetConnectionString("Default")); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
/// <summary> /// Init DI Containers. /// </summary> public static void InitDI() { var container = new Container(); container.Options.DefaultScopedLifestyle = new WebRequestLifestyle(); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); DIModule.InitializeIoc(container, Lifestyle.Scoped); //GlobalConfiguration.Configuration.DependencyResolver // = new SimpleInjectorWebApiDependencyResolver(container); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); }
// 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); //Options Pattern Implementation //Configure AppSettings section var appConfig = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appConfig); //Using AppSettings var appSettings = appConfig.Get <AppSettings>(); string connectionString = appSettings.NoteAppConnectionString; //Read a value from the configuration file appSettings.json //string hosts = Configuration.GetValue<string>("AllowedHosts"); //Jwt token authentication configuration var secret = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(secret), ValidateIssuer = false, ValidateAudience = false }; }); //Call the RegisterModule method that register all the repositories and the NoteDbContext class DIModule.RegiseterModule(services, connectionString); //Registering services services.AddTransient <IUserService, UserService>(); services.AddTransient <INoteService, NoteService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //CORS services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Configuring AppSettings section var appConfig = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appConfig); // Using AppSettings //Configure jwt authentication: var appSettings = appConfig.Get <AppSettings>(); var secret = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; } ).AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(secret), ValidateIssuer = false, ValidateAudience = false }; } ); // IUserServce => new UserService(); services.AddTransient <IUserService, UserService>(); // INoteService => new NoteService(); services.AddTransient <IBookService, BookService>(); //Configure connection string: DIModule.RegisterModule(services, appSettings.LibraryAppConnectionString); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseSystemd() .ConfigureServices( (hostContext, services) => { DIModule.RegisterDependency(services); services.AddDbContext <CorrectItDbContext>( options => options.UseMySql( hostContext.Configuration.GetConnectionString("CorrectItWeb"), b => b.MigrationsAssembly("Infrastructure.Data.Sql")), optionsLifetime: ServiceLifetime.Singleton); services.AddHostedService <Worker>(); services.AddMemoryCache(); });
// 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).AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);; //get connection string from appsettings.json var connectionString = Configuration.GetConnectionString("DefaultConnection"); //important!!! - > every constructor that requires IUserService, this instantiates UserService instead !!!!! services.AddTransient <IUserService, UserService>(); services.AddTransient <IEmailService, EmailService>(); DIModule.RegisterModule(services, connectionString); //Server = CRMT-03; Database=MilanEmailDataBase; Trusted_Connection=True; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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.AddAutoMapper(); DIModule.RegisterRepositories(services, Configuration["ConnectionStrings:BooksDatabase"]); services.AddTransient <IAuthorService, AuthorService>(); services.AddTransient <INovelService, NovelService>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public void baasic_client_infrastructure_dependency_injection_get_service_simple_test() { this.fixture.Target.Should().NotBeNull(); Action execute = () => { var module = new DIModule(); module.Load(this.fixture.Target); }; execute.ShouldNotThrow(); var expected = this.fixture.Target.GetService(typeof(IHttpClientFactory)); expected.Should().NotBeNull(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); MapperConfig.ConfigureMapping(); //TODO: удалить после завершения разработки Database.SetInitializer(new InitializerDb()); // внедрение зависимостей NinjectModule module = new DIModule(); var kernel = new StandardKernel(module); DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); }
public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetValue <string>("LamazonConnectionString"); DIModule.RegisterModule(services, connectionString); services.AddTransient <IUserService, UserService>(); services.AddTransient <IOrderService, OrderService>(); services.AddTransient <IProductService, ProductService>(); _ = services.AddAutoMapper(); services.AddControllers(); }
static void Main(string[] args) { var serviceCollection = new ServiceCollection(); DIModule.ConfigureServices <Program>(serviceCollection); var serviceProvider = serviceCollection.AddLogging(cfg => cfg.AddConsole()).Configure <LoggerFilterOptions>(cfg => cfg.MinLevel = LogLevel.Debug).BuildServiceProvider(); var logger = serviceProvider.GetService <ILogger <Program> >(); IGameService gameService = serviceProvider.GetService <IGameService>(); gameService.Start( (args.Length > 0 ? args[0] : null), (args.Length > 1 ? args[1] : null)); Thread.Sleep(500); }
public void baasic_client_infrastructure_dependency_injection_get_service_complex_error_test() { this.fixture.Target.Should().NotBeNull(); Action execute = () => { var module = new DIModule(); module.Load(this.fixture.Target); }; execute.ShouldNotThrow(); execute = () => { var expected = this.fixture.Target.GetService(typeof(ITokenClient)); }; execute.ShouldThrow <Exception>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); }); services.AddCors(opt => { opt.AddPolicy("CorsPolicy", policy => { policy.AllowAnyMethod().AllowAnyHeader().WithOrigins("http://localhost:3000"); }); }); DIModule.AddApplicationService(services, _config); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetValue <string>("RentacarConnectionString"); DIModule.RegisterModule(services, connectionString); services.AddTransient <IAddEquipmentService, AdditionalEquipmentService>(); services.AddTransient <IVehicleService, VehicleService>(); services.AddTransient <IInvoiceService, InvoiceService>(); services.AddTransient <IOrderService, OrderService>(); services.AddTransient <IUserService, UserService>(); services.ConfigureApplicationCookie(options => { options.Cookie.HttpOnly = true; //options.Cookie.MaxAge options.ExpireTimeSpan = TimeSpan.FromMinutes(60); options.LoginPath = "/User/Login"; options.AccessDeniedPath = "/User/Login"; options.SlidingExpiration = true; }); services.AddAutoMapper(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "RentaMkDrive API", Version = "v1" }); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(options => { var resolve = options.SerializerSettings.ContractResolver; if (resolve != null) { (resolve as DefaultContractResolver).NamingStrategy = null; } //options.SerializerSettings = ReferenceLoopHandling.Ignore; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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; }); // configuring appsettings section var appConfig = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appConfig); // using appsettings var appSettings = appConfig.Get <AppSettings>(); DIModule.RegisterModule(services, appSettings.LamazonDbContext); services.Configure <IdentityOptions>(opt => { }); services.ConfigureApplicationCookie(options => { options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(60); options.LoginPath = "/Users/Login"; options.AccessDeniedPath = "/Home/"; options.SlidingExpiration = true; }); //register services services.AddTransient <IUserService, UserService>(); services.AddTransient <IOrderService, OrderService>(); services.AddTransient <IProductService, ProductService>(); // Register automapper services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public void baasic_client_infrastructure_dependency_injection_get_service_complex_success_test() { this.fixture.Target.Should().NotBeNull(); Action execute = () => { var module = new DIModule(); module.Load(this.fixture.Target); }; execute.ShouldNotThrow(); execute = () => { this.fixture.Target.Register <IDependencyResolver>(() => this.fixture.Target); this.fixture.Target.Register <IClientConfiguration>(() => this.fixture.ClientConfiguration.Object); var expected = this.fixture.Target.GetService(typeof(ITokenClient)); }; execute.ShouldNotThrow(); }