// 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_2);

            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(connectionString)
                                                 );
            services.AddTransient <IUnitOfWork, UnitOfWork>();
            services.AddTransient <IRestaurantService, RestaurantService>();
            services.AddTransient <IAreaService, AreaService>();
            services.AddTransient <IMealService, MealService>();
            services.AddTransient <IMealCategoryService, MealCategoryService>();
            services.AddTransient <IMealTypeService, MealTypeService>();

            services.AddTransient <IRestaurantRepository, RestaurantRepository>();
            services.AddTransient <IAreaRepository, AreaRepository>();
            services.AddTransient <IMealRepository, MealRepository>();

            // Register Automaper
            var apiMappings = new MappingProfiles();

            services.AddAutoMapper(typeof(Startup));

            // Auto Mapper Configurations
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(apiMappings);
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);
        }
Beispiel #2
0
        /// <summary>
        ///     Builds <see cref="ServiceProvider"/> for registered services and mapping profiles.
        /// </summary>
        /// <returns>The <see cref="ServiceProvider"/>.</returns>
        public ServiceProvider Build()
        {
            var mapper = new MapperConfiguration(mc => MappingProfiles.ForEach(mc.AddProfile)).CreateMapper();

            Services.AddSingleton(mapper);

            return(Services.BuildServiceProvider());
        }
        public OrderServiceTests()
        {
            var mappingProfiles = new MappingProfiles();
            var configuration   = new MapperConfiguration(cfg => cfg.AddProfile(mappingProfiles));

            _mapper = new Mapper(configuration);
            _sut    = new OrderService(_orderRepository, _mapper, _cartService, _productService);
        }
Beispiel #4
0
        public ProductServiceTests()
        {
            var mappingProfiles = new MappingProfiles();
            var configuration   = new MapperConfiguration(cfg => cfg.AddProfile(mappingProfiles));

            _mapper = new Mapper(configuration);
            _sut    = new ProductService(_productRepository, _mapper, _dateTimeService);
        }
Beispiel #5
0
        public UserServiceTests()
        {
            var mappingProfiles = new MappingProfiles();
            var configuration   = new MapperConfiguration(cfg => cfg.AddProfile(mappingProfiles));

            _mapper = new Mapper(configuration);
            _sut    = new UserService(_userRepository, _cartRepository, _membershipRepository, _mapper, _dateTimeService,
                                      _addressRepository, _paymentRepository);
        }
        public DiscountServiceTests()
        {
            var mappingProfiles = new MappingProfiles();
            var configuration   = new MapperConfiguration(cfg => cfg.AddProfile(mappingProfiles));

            _mapper = new Mapper(configuration);
            _sut    = new DiscountService(_mapper, _productRepository, _discountRepository, _membershipRepository,
                                          _createDiscountValidator, _updateDiscountValidator);
        }
Beispiel #7
0
        public static void RegisterComponents()
        {
            var container = new UnityContainer();

            // register all your components with the container here
            // it is NOT necessary to register your controllers

            // e.g. container.RegisterType<ITestService, TestService>();gist
            //container.RegisterSingleton(typeof(MappingProfiles));

            //var config = new MapperConfiguration(ctx =>
            //{
            //    ctx.CreateMap<customer, Customer>();
            //    ctx.CreateMap<order, Order>();
            //});
            //IMapper mapper = config.CreateMapper();
            //container.RegisterInstance(mapper);
            container.RegisterInstance(new SampleDbEntities());
            container.RegisterInstance(MappingProfiles.ConfigureMapper());
            container.RegisterType <ICustomerRepository, CustomerRepository>();
            container.RegisterType <IOrderRepository, OrderRepository>();
            container.RegisterType <IOrderItemRepository, OrderItemRepository>();
            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.ConfigureLogs(Configuration);

            services.ConfigureCors();
            services.ConfigureSignalR();
            services.ConfigureHangfire(Configuration);

            services.ConfigureDbContext(Configuration);
            services.ConfigureSwagger();
            services.ConfigureTokenAuth(Configuration);
            services.AddResponseCaching();
            services.ConfigureCompression();
            services.ConfigureHealthChecks(Configuration);
            services.ConfigureDetection();

            services.AddHttpContextAccessor();
            services.AddMvc(config =>
            {
                config.Filters.Add(typeof(ApiValidationFilterAttribute));
                config.EnableEndpointRouting = false;
            }).AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);

            services.AddTransient <IUnitOfWork, UnitOfWork>();
            services.AddTransient <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped(typeof(IGenericRepository <>), typeof(GenericRepository <>));
            services.AddTransient <IAmazonS3Service, AmazonS3Service>();
            services.AddTransient <IFileService, Services.Impls.FileService>();
            services.AddTransient <IAccountService, Services.Impls.AccountService>();
            services.AddTransient <IEmailService, EmailService>();
            services.AddTransient <IPollService, PollService>();
            services.AddTransient <IQuestionService, QuestionService>();
            services.AddTransient <IConceptService, ConceptService>();
            services.AddTransient <IAnswerService, AnswerService>();
            services.AddTransient <IUserService, UserService>();
            services.AddTransient <ITagService, TagService>();
            services.AddTransient <IDishService, DishService>();
            services.AddTransient <IEatService, EatService>();
            services.AddTransient <IDeviceService, DeviceService>();
            services.AddTransient <IMismeBackgroundService, MismeBackgroundService>();
            services.AddTransient <ITipService, TipService>();
            services.AddTransient <IReminderService, ReminderService>();
            services.AddTransient <IResultService, ResultService>();
            services.AddTransient <ISettingService, SettingService>();
            services.AddTransient <IGeneralContentService, GeneralContentService>();
            services.AddTransient <IContactUsService, ContactUsService>();
            services.AddTransient <IRewardCategoryService, RewardCategoryService>();
            services.AddTransient <IRewardService, RewardService>();
            services.AddTransient <IUserStatisticsService, UserStatisticsService>();
            services.AddTransient <ICompoundDishService, CompoundDishService>();
            services.AddTransient <ICutPointService, CutPointService>();
            services.AddTransient <IRewardHelper, RewardHelper>();
            services.AddTransient <IUserReferralService, UserReferralService>();
            services.AddTransient <IScheduleService, ScheduleService>();
            services.AddTransient <INotificationService, NotificationService>();
            services.AddTransient <ISoloQuestionService, SoloQuestionService>();
            services.AddTransient <ISubscriptionService, MismeAPI.Service.Impls.SubscriptionService>();
            services.AddTransient <IAppService, AppService>();
            services.AddTransient <IPaymentService, PaymentService>();
            services.AddTransient <IPaypalService, PaypalService>();
            services.AddTransient <IProductService, Services.Impls.ProductService>();
            services.AddTransient <IReportService, ReportService>();
            services.AddTransient <IProfileHelthHelper, ProfileHelthHelper>();
            services.AddTransient <IAppleAppStoreService, AppleAppStoreService>();

            var provider              = services.BuildServiceProvider();
            var amazonS3Service       = provider.GetService <IAmazonS3Service>();
            var userStatisticsService = provider.GetService <IUserStatisticsService>();
            var contextAccessor       = provider.GetService <IHttpContextAccessor>();

            var apiMappings = new MappingProfiles(amazonS3Service, userStatisticsService, contextAccessor);

            services.AddAutoMapper(x => x.AddProfile(apiMappings), typeof(Startup));

            var stripeApiKey = Configuration.GetSection("Stripe")["ApiKey"];

            StripeConfiguration.ApiKey = stripeApiKey;
        }