示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .AddFluentValidation(validator =>
                                 validator.RegisterValidatorsFromAssemblyContaining <Startup>())
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //services.AddDtoValidation(services);

            var oAuthConnection = Configuration["Storage:SqlServer:OAuthTimeTracker:ConnectionString"];

            services.AddOAuth(oAuthConnection);

            // Add domain policies
            services.AddDomainPolicies();

            // Add domainn repositories
            services.AddDomainRepositories();

            // Add domain services
            services.AddDomainServies();

            // Add Database Initializer
            services.AddScoped <IDbInitializer, DbInitializer>();

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                //c.SwaggerDoc("v1", new Info { Title = "Time tracker - API docs", Version = "v1" });
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "Time tracker - API docs",
                    Description    = "Time tracker API documentations",
                    TermsOfService = "None",
                    Contact        = new Contact
                    {
                        Name  = "2Click Solutions",
                        Email = string.Empty,
                        Url   = "https://github.com/quanntt0203"
                    }
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"TimeTrackerApi.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });

            ResolverFactory.SetProvider(services);
        }
示例#2
0
        public static void RegisterIoC(IServiceCollection services)
        {
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            //Services
            services.AddScoped <IUserService, UserService>();
            //SQL Generator
            services.AddScoped <ISqlGenerator <User>, SqlGenerator <User> >();

            ResolverFactory.SetProvider(services.BuildServiceProvider());
        }
示例#3
0
        public static void RegisterIoC(IServiceCollection services)
        {
            services.AddScoped(UnitOfWorkFactory);
            services.AddScoped <IDapperContext, DapperContext>();
            services.AddScoped <CQRS.ISession, Session>();
            services.AddScoped <IDatabase, Database>();

            services.AddScoped <IAnimalService, AnimalService>();

            ResolverFactory.SetProvider(services.BuildServiceProvider());
        }
示例#4
0
        public static IServiceCollection AddServices(this IServiceCollection services, IConfiguration configuration)
        {
            ResolverFactory.SetProvider(services.BuildServiceProvider());

            services.AddSingleton(typeof(IAppLogger <>), typeof(LoggerAdapter <>));

            services.AddScoped(typeof(IRepository <>), typeof(EfRepository <>));

            services.AddAutoMapper(Assembly.GetExecutingAssembly());

            if (configuration.GetValue <string>("UseResilientHttp") == bool.TrueString)
            {
                services.AddTransient <IResilientHttpClientFactory, ResilientHttpClientFactory>();
                services.AddTransient <IHttpClient, ResilientHttpClient>(sp => sp.GetService <IResilientHttpClientFactory>().CreateResilientHttpClient());
            }
            else
            {
                services.AddTransient <IHttpClient, StandardHttpClient>();
            }

            return(services);
        }
示例#5
0
        public static IServiceCollection AddServices(this IServiceCollection services)
        {
            services.AddHttpClient();

            services.AddScoped <ITokenProvider, TokenProvider>();

            services.AddSingleton <IPasswordHasher <User>, PasswordHasher <User> >();

            services.AddScoped <IAccountService, AccountManager>();

            services.Scan(scan =>
            {
                scan.FromCallingAssembly()
                .AddClasses()
                .AsMatchingInterface()
                .WithScopedLifetime();
            });

            ResolverFactory.SetProvider(services.BuildServiceProvider());

            return(services);
        }
示例#6
0
        private void RegisterIoC(IServiceCollection services)
        {
            services.AddScoped <WebApiUserManager, WebApiUserManager>();

            services.AddScoped <WebApiRoleManager, WebApiRoleManager>();

            services.AddScoped <IUnitOfWork, UnitOfWork>();

            services.AddScoped <ICategoryService, CategoryService>();

            services.AddScoped <ICustomerCustomerDemoService, CustomerCustomerDemoService>();

            services.AddScoped <ICustomerDemographicsService, CustomerDemographicsService>();

            services.AddScoped <ICustomersService, CustomersService>();

            services.AddScoped <IEmployeesService, EmployeesService>();

            services.AddScoped <IEmployeeTerritoriesService, EmployeeTerritoriesService>();

            services.AddScoped <IOrderDetailsService, OrderDetailsService>();

            services.AddScoped <IOrdersService, OrdersService>();

            services.AddScoped <IProductsService, ProductsService>();

            services.AddScoped <IRegionService, RegionService>();

            services.AddScoped <IShippersService, ShippersService>();

            services.AddScoped <ISuppliersService, SuppliersService>();

            services.AddScoped <ITerritoriesService, TerritoriesService>();

            services.AddScoped <IClientService, ClientService>();

            ResolverFactory.SetProvider(services.BuildServiceProvider());
        }