Beispiel #1
0
        /// <summary>
        /// 添加Unit Of Work
        /// </summary>
        /// <param name="services"></param>
        public static void AddUow(this Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            #region UOW

            services.TryAddSingleton <IUnitOfWorkDefaultOptions, UnitOfWorkDefaultOptions>();

            services.AddTransient <ICurrentUnitOfWorkProvider, AsyncLocalCurrentUnitOfWorkProvider>();

            services.AddTransient <UnitOfWorkBase, EfCoreUnitOfWork>();

            services.AddTransient <IUnitOfWork, EfCoreUnitOfWork>();

            services.AddTransient <IUnitOfWorkManager, UnitOfWorkManager>();

            #endregion

            #region EntityFrameworkCore

            services.TryAddSingleton <IDbContextTypeMatcher, DbContextTypeMatcher>();

            services.AddTransient <IEfCoreTransactionStrategy, DbContextEfCoreTransactionStrategy>();

            services.AddTransient <IDbContextResolver, DefaultDbContextResolver>();

            services.AddTransient(typeof(IDbContextProvider <>), typeof(UnitOfWorkDbContextProvider <>));

            #endregion
        }
        public void ConfigureServices
            (Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddControllers();

            services.AddDbContext <Banking.Data.Context.DatabaseContext>(options =>
            {
                // UseSqlServer -> using Microsoft.EntityFrameworkCore;
                // GetConnectionString -> using Microsoft.Extensions.Configuration;
                options.UseSqlServer
                    (Configuration.GetConnectionString("BankingConnectionString"));
            });

            services.AddSwaggerGen(current =>
            {
                current.SwaggerDoc(name: "v1",
                                   info: new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Version = "v1",
                    Title   = "Banking Microservice",
                });
            });

            services.AddMediatR(handlerAssemblyMarkerTypes: typeof(Startup));

            Infrastructure.IoC.DependencyContainer.RegisterServices(services: services);
        }
        public static void RegisterServices
            (Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            // Domain Bus
            //services.AddTransient
            //	<Domain.Core.Bus.IEventBus, Bus.RabbitMQEventBusSimple>();

            // Updated!
            services.AddSingleton
            <Domain.Core.Bus.IEventBus, Bus.RabbitMQEventBus>(sp =>
            {
                Microsoft.Extensions.DependencyInjection.IServiceScopeFactory serviceScopeFactory =
                    sp.GetRequiredService <Microsoft.Extensions.DependencyInjection.IServiceScopeFactory>();

                return(new Bus.RabbitMQEventBus(sp.GetService <MediatR.IMediator>(), serviceScopeFactory));
            });

            // Application Service(s)
            services.AddTransient
            <Banking.Application.Interfaces.IAccountService,
             Banking.Application.Services.AccountService>();

            // Data
            services.AddTransient
            <Banking.Data.Context.DatabaseContext>();

            services.AddTransient
            <Banking.Domain.Interfaces.IAccountRepository,
             Banking.Data.Repositories.AccountRepository>();
        }
 public static void RegisterServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services, IConfiguration configuration)
 {
     services.AddDbContext <dbBuildTicketContext>(options => options.UseSqlServer(configuration.GetConnectionString("DevConnection")));
     services.AddScoped <ITicketDomain, TicketDomain>();
     services.AddScoped <IBuildRepository, BuildRepository>();
     services.AddScoped <IBuildTicketService, BuildTicketService>();
 }
 // method runs after Constructor is done in first run
 // parameter of type IServiceCollection is passed into this method
 // doesn't return anything
 public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
 {
     services.AddDbContext <Models.ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreProducts:ConnectionString"]));
     services.AddDbContext <Models.AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreIdentity:ConnectionString"]));
     services.AddIdentity <Microsoft.AspNetCore.Identity.IdentityUser, Microsoft.AspNetCore.Identity.IdentityRole>()
     .AddEntityFrameworkStores <BilliardStore.Models.AppIdentityDbContext>()
     .AddDefaultTokenProviders();
     services.AddTransient <Models.IProductRepository, Models.EFProductRepository>();
     services.AddScoped <Models.Cart>(sp => Models.SessionCart.GetCart(sp));
     services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();
     services.AddTransient <Models.IOrderRepository, Models.EFOrderRepository>();
     services.AddTransient <SendGrid.ISendGridClient>((s) =>
     {
         return(new SendGrid.SendGridClient(Configuration.GetValue <string>("SendGrid:Key")));
     });
     services.AddTransient <Braintree.IBraintreeGateway>((s) =>
     {
         return(new Braintree.BraintreeGateway(
                    Configuration.GetValue <string>("Braintree:Environment"),
                    Configuration.GetValue <string>("Braintree:MerchantId"),
                    Configuration.GetValue <string>("Braintree:PublicKey"),
                    Configuration.GetValue <string>("Braintree:PrivateKey")));
     });
     services.AddTransient <SmartyStreets.IClient <SmartyStreets.USStreetApi.Lookup> >((s) =>
     {
         return(new SmartyStreets.ClientBuilder(
                    Configuration.GetValue <string>("SmartyStreets:AuthId"),
                    Configuration.GetValue <string>("SmartyStreets:AuthToken")
                    ).BuildUsStreetApiClient());
     });
     services.AddMvc();
     services.AddMemoryCache();
     services.AddSession();
 }                                                                                                                                                                                                                                                                                        // makes EFProductRepository take the place of IProductRepository in the code
 public static ISqlRepositoryBuilder AddSqlRepository(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action <SqlRepositoryOptions> configure)
 {
     services.Configure(configure);
     services.AddSingleton(typeof(OfaSchlupfer.Model.IExternalRepositoryModelType), typeof(SqlRepositoryModelType));
     services.AddTransient(typeof(SqlRepositoryModel), typeof(SqlRepositoryImplementation));
     return(new SqlRepositoryBuilder(services));
 }
        public void ConfigureServices
            (Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddControllers();

            // Note:
            services.AddTransient
            <Microsoft.AspNetCore.Http.IHttpContextAccessor,
             Microsoft.AspNetCore.Http.HttpContextAccessor>();

            // Note:
            //services.AddTransient<Dtx.Logging.ILogger, Dtx.Logging.NLogAdapter>(); // Compile Error!

            //services.AddTransient<Dtx.Logging.ILogger<>, Dtx.Logging.NLogAdapter<>>(); // Compile Error!

            //services.AddSingleton
            //	(serviceType: typeof(Dtx.Logging.ILogger<>),
            //	implementationType: typeof(Dtx.Logging.NLogAdapter<>)); // Runtime Error!

            services.AddTransient
                (serviceType: typeof(Dtx.Logging.ILogger <>),
                implementationType: typeof(Dtx.Logging.NLogAdapter <>));

            //services.AddTransient
            //	(serviceType: typeof(Dtx.Logging.ILogger<>),
            //	implementationType: typeof(Dtx.Logging.Log4NetAdapter<>));
        }
Beispiel #8
0
        private void ConfigureServicesSwagger(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddSwaggerGen(c =>
            {
                c.AddSecurityDefinition("Bearer", new ApiKeyScheme {
                    In = "header", Description = "Please insert JWT Bearer into the field", Name = "Authorization", Type = "apiKey"
                });
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "Support Wheel of Fate API",
                    Description    = "A REST API to select two engineers at random to both complete a half day of support each.",
                    TermsOfService = "None",
                    Contact        = new Contact {
                        Name = "Italo Pessoa", Email = "", Url = "https://github.com/italopessoa/support-wheel-of-fate"
                    },
                    License = new License {
                        Name = "MIT", Url = "https://opensource.org/licenses/MIT"
                    }
                });

                //Set the comments path for the swagger json and ui.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "BAU.Api.xml");
                c.IncludeXmlComments(xmlPath);
            });
        }
Beispiel #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Entity Framework services to the services container.
            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext <PhotoGalleryContext>(options =>
                                                options.UseSqlServer(Configuration["Data:PhotoGalleryConnection:ConnectionString"]));

            // Repositories
            services.AddScoped <IPhotoRepository, PhotoRepository>();
            services.AddScoped <IAlbumRepository, AlbumRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserRoleRepository, UserRoleRepository>();
            services.AddScoped <IRoleRepository, RoleRepository>();
            services.AddScoped <ILoggingRepository, LoggingRepository>();

            // Services
            services.AddScoped <IMembershipService, MembershipService>();
            services.AddScoped <IEncryptionService, EncryptionService>();

            services.AddAuthentication();

            // Polices
            services.AddAuthorization(options =>
            {
                // inline policies
                options.AddPolicy("AdminOnly", policy =>
                {
                    policy.RequireClaim(ClaimTypes.Role, "Admin");
                });
            });

            // Add MVC services to the services container.
            services.AddMvc();
        }
Beispiel #10
0
 private static void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
 {
     services
     .AddElsaCore()
     .AddConsoleActivities()
     .AddTimerActivities(options => options.Configure(x => x.SweepInterval = Duration.FromSeconds(1)))
     .AddWorkflow <RecurringTaskWorkflow>();
 }
        public static void UseRavenDbWithInjectedDocumentStore(this SchedulerBuilder.PersistentStoreOptions options,
                                                               Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            options.SetProperty(StdSchedulerFactory.PropertyJobStoreType,
                                typeof(RavenJobStore).AssemblyQualifiedNameWithoutVersion());

            services.AddSingleton <IJobStore, RavenJobStore>();
        }
Beispiel #12
0
 private static void ConfigureServices(IConfiguration configuration, Microsoft.Extensions.DependencyInjection.IServiceCollection services)
 {
     services.Configure <AppSettings>
         (configuration.GetSection(nameof(AppSettings)));
     services.AddSingleton <PromotionEngine>();
     services.AddScoped <IblActivePromotion, blActivePromotion>();
     services.AddScoped <IblSkuIdPrice, blSkuIdPrice>();
 }
Beispiel #13
0
        /// <summary>
        /// 添加管理提供者
        /// </summary>
        /// <param name="service"></param>
        public static void AddManageProvider(this IServiceCollection service)
        {
            service.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            service.TryAddSingleton <IManageProvider, ManageProvider2>();
            //service.TryAddSingleton(ManageProvider2.Provider);

            ManageProvider.Provider = service.BuildServiceProvider().GetService <IManageProvider>();
        }
Beispiel #14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddMvc((options) =>
            {
            })

            .AddApplicationPart(typeof(SimulatorController).GetTypeInfo().Assembly);
        }
Beispiel #15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddMvc();

            // به کنترلرها تزریق کنیم، به این دستور نیاز داریم DatabaseContext در صورتی که بخواهیم
            services.AddDbContext <Models.DatabaseContext>(options =>
                                                           options.UseSqlServer(Configuration.GetConnectionString(name: "DatabaseContext")));
        }
Beispiel #16
0
        public static IServiceCollection AddMongoDB(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action <MongoDBOptions> setupAction)
        {
            var mongoOptions = new MongoDBOptions();

            setupAction(mongoOptions);
            return(services
                   .AddSingleton(provider => mongoOptions)
                   .AddMongoDB(new MongoDBConfiguration(mongoOptions)));
        }
 public static void RegisterMongoClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection servicesBuilder)
 {
     servicesBuilder.AddSingleton <IMongoClient, MongoClient>(s =>
     {
         var uri      = s.GetRequiredService <IConfiguration>().GetValue <string>("MongoUri");
         var settings = MongoClientSettings.FromConnectionString(uri);
         return(new MongoClient(settings));
     });
 }
Beispiel #18
0
 public static void AddMicroORM(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string connectionString, ILog logger = null)
 {
     services.
     AddTransient <ILog>(p => logger ?? new ConsoleLogWriter()).
     AddSingleton <SQLDatabaseOptions>((p) => new SQLDatabaseOptions()
     {
         ConnectionString = connectionString
     }).
     AddTransient <Factory>();
 }
 public static void RegisterMongoDbRepositories(this Microsoft.Extensions.DependencyInjection.IServiceCollection servicesBuilder)
 {
     servicesBuilder.AddSingleton <CustomerRepository>(s =>
     {
         var mongoClient  = s.GetRequiredService <IMongoClient>();
         var databaseName = s.GetRequiredService <IConfiguration>().GetValue <string>("DatabaseName");
         return(new CustomerRepository(mongoClient, databaseName));
     });
     //add additional repositories >>here<<
 }
        Clone(Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection)
        {
            Microsoft.Extensions.DependencyInjection.IServiceCollection clone =
                new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            foreach (Microsoft.Extensions.DependencyInjection.ServiceDescriptor service in serviceCollection)
            {
                clone.Add(service);
            }

            return(clone);
        }
        public ServiceHostBuilder()
        {
            this.m_properties = new System.Collections.Generic.Dictionary <object, object>();
            this.m_context    = new Microsoft.Extensions.Hosting.HostBuilderContext(this.m_properties);
            this.m_context.HostingEnvironment = new HostingEnvironment();

            this.m_hostServices         = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            this.m_configurationBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder();

            this.m_hostBuilder = new Microsoft.Extensions.Hosting.HostBuilder();
        }
        public static void AddRabbitMqHandler <T>(this IServiceCollection services, bool subscribeToQueue) where T : class
        {
            var sp       = services.BuildServiceProvider();
            var bus      = sp.GetService <IBus>();
            var repoLite = sp.GetService <IRabbitMqBackupLiteDbService>();
            var repo     = sp.GetService <IRabbitMqBackupService>();

            var obj = (T)Activator.CreateInstance(typeof(T), services, bus, repo, repoLite, subscribeToQueue);

            services.AddSingleton(obj);
        }
Beispiel #23
0
        public static IServiceCollection AddEmerald <TServiceScopeFactory>(this IServiceCollection services, IApplicationConfiguration configuration, Action <EmeraldOptions> options) where TServiceScopeFactory : class, Emerald.System.IServiceScopeFactory
        {
            var serviceCollection          = new System.ServiceCollection(services);
            var applicationName            = configuration.Environment.ApplicationName;
            var emeraldSystemBuilderConfig = EmeraldSystemBuilder.Create <TServiceScopeFactory>(applicationName, serviceCollection);
            var emeraldOptions             = new EmeraldOptions(emeraldSystemBuilderConfig, configuration);

            options(emeraldOptions);
            Registry.EmeraldSystem = emeraldSystemBuilderConfig.RegisterDependencies().Build(services.BuildServiceProvider());
            return(services);
        }
Beispiel #24
0
        public static void AddLogixSession(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration)
        {
            double sessionIdleTimeout = System.Convert.ToDouble(configuration["ConnectAuthentication:SessionLifeTime"]);

            services.AddSession
            (
                options =>
            {
                options.IdleTimeout = System.TimeSpan.FromSeconds(sessionIdleTimeout);
            }
            );
        }
Beispiel #25
0
        public void Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient <ContentController>();

            serviceCollection.AddScoped <IItemFactory, ItemFactory>();
            serviceCollection.AddScoped <IItemSearchFactory, ItemSearchFactory>();
            serviceCollection.AddScoped <IContextProvider, ContextProvider>();
            serviceCollection.AddSingleton <IModelAssemblyProvider, ModelAssemblyProvider>();
            serviceCollection.AddSingleton <ISpawnProvider, SpawnProvider>();
            serviceCollection.AddSingleton <ITemplateMapProvider, TemplateMapProvider>();
            serviceCollection.AddScoped <ISearchResultsAdapter, SearchResultsAdapter>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddAuthentication("Bearer")
            .DSAddJwtBearer(options =>
            {
                options.AudienceAuthorityResolver = new CognitoUserPoolResolver(new DataContext());
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddScoped <IIAASService, AWSCognitoService>();
            services.AddScoped <DataContext>();
        }
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddAuthentication();

            services.AddSignalR();
            // Add framework services.
            //services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            // Add MVC services to the services container.
            services.AddMvc()
            .AddJsonOptions(opts =>
            {
                opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
        }
Beispiel #28
0
        // This method gets called by the runtime.
        // Use this method to add services to the container.
        public void ConfigureServices(
            Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                // TODO: Add configurable proxy list
                // options.KnownProxies.Add(IPAddress.Parse("10.0.0.100"));
            });

            services.AddSingleton(new SqlService());


            services.AddMvc();
        }
Beispiel #29
0
        public void ConfigureRepositoryServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            //services.AddDbContext<SupplyOfProductsContext>(options =>
            //    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
            //));

            // Add Repositories.
            services.AddSingleton <IGenericContext, SupplyOfProductsContext>();
            services.AddTransient <IProductRepository, ProductRepository>();
            services.AddTransient <IProductSupplyRepository, ProductSupplyRepository>();
            services.AddTransient <IWorkerRepository, WorkerRepository>();
            services.AddTransient <IWorkerInWorkPlaceRepository, WorkerInWorkPlaceRepository>();
            services.AddTransient <IWorkPlaceRepository, WorkPlaceRepository>();
            services.AddTransient <IProductStockRepository, ProductStockRepository>();
            services.AddTransient <ISupplyScheduledRepository, SupplyScheduledRepository>();
            services.AddTransient <IConfigSupplyRepository, ConfigSupplyRepository>();
        }
Beispiel #30
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddAspNetCoreSystemServices();
            services.AddMvc()
            .AddJsonOptions(
                s => SF.Core.Serialization.Newtonsoft.JsonSerializer.ApplySetting(
                    s.SerializerSettings,
                    new SF.Core.Serialization.JsonSetting
            {
                IgnoreDefaultValue = true,
                WithType           = false
            })
                );

            var ins = HygouApp.Setup(SF.Core.Hosting.EnvironmentType.Production, services)
                      .With(sc =>
                            sc.AddAspNetCoreSupport()
                            .AddAccessTokenHandler(
                                "HYGOU",
                                "123456",
                                null,
                                null
                                )
                            )
                      .OnEnvType(
                t => t != EnvironmentType.Utils,
                sc =>
            {
                sc.AddNetworkService();
                sc.AddAspNetCoreServiceInterface();
                sc.AddIdentityServer4Support();
                var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("system"));
                sc.AddSingleton <ISigningCredentialStore>(
                    new DefaultSigningCredentialsStore(
                        new Microsoft.IdentityModel.Tokens.SigningCredentials(
                            key,
                            SecurityAlgorithms.HmacSha256
                            )
                        ));
            }
                )
                      .Build();

            return(ins.ServiceProvider);
        }