/// <summary>
 /// Initializes a new instance of the <see cref="UsersService"/> class.
 /// </summary>
 /// <param name="unitOfWork">The unit of work.</param>
 /// <param name="tokenDataProvider">The token data provider.</param>
 public UsersService(IUnitOfWork unitOfWork, IUsersDataProvider tokenDataProvider, ICustomersDataProvider customersDataProvider)
 {
     this.unitOfWork            = unitOfWork;
     usersRepository            = this.unitOfWork.CreateGenericRepository <User>();
     customerUsersRepository    = this.unitOfWork.CreateGenericRepository <CustomerUser>();
     userRolesRepository        = this.unitOfWork.CreateGenericRepository <UserRole>();
     this.tokenDataProvider     = tokenDataProvider;
     this.customersDataProvider = customersDataProvider;
 }
 // Dependency Injection: ASP.NET Core will automatically populate controller constructor arguments by resolving
 // services from the DI container. If needed, those objects will be created by calling constructors
 // whose own arguments will be provided by DI, and so on recursively until the whole object graph
 // needed has been constructed.
 //
 // Logging: Here a logger is dependency injected and then used to log to the loggers added to the LoggerFactory.
 //          The category of CustomersController has been added using the <T> of CustomersController. This information
 //          will be written out in the log information. The logging information is written throughout the methods below.
 //
 // Localization: Here we are injecting a ResourceManager that will be used by the api methods below for localizing content.
 public CustomersController(ICustomersDataProvider customersDataProvider,
                            ResourceManager resourceManager,
                            IStringLocalizer <CustomersController> localizer,
                            ILogger <CustomersController> logger)
 {
     _customersDataProvider = customersDataProvider;
     _resourceManager       = resourceManager;
     _localizer             = localizer;
     _logger = logger;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomersService"/> class.
 /// </summary>
 /// <param name="usersService">The users service.</param>
 /// <param name="customersDataProvider">The customers data provider.</param>
 /// <param name="unitOfWork">The unit of work.</param>
 public CustomersService(
     IUsersService usersService,
     ICustomersDataProvider customersDataProvider,
     IUnitOfWork unitOfWork
     )
 {
     this.customersDataProvider                   = customersDataProvider;
     this.unitOfWork                              = unitOfWork;
     this.customerUserRolesRepository             = this.unitOfWork.CreateGenericRepository <CustomerUserRole>();
     this.customerUserRolesPersmissionsRepository = this.unitOfWork.CreateGenericRepository <CustomerUserRoleToPermissionMapping>();
     this.usersService                            = usersService;
 }
Exemple #4
0
        /// <summary>
        /// Creates a test instance of the CustomersController passing in a ICustomersDataProvider, ResourceManager and ILogger
        /// </summary>
        private CustomersController CreateTestCustomersController(ICustomersDataProvider customersDataProvider, TestLogger <CustomersController> testLogger)
        {
            var controller = new CustomersController(customersDataProvider,
                                                     _serviceProvider.GetRequiredService <ResourceManager>(),
                                                     _serviceProvider.GetRequiredService <IStringLocalizer <CustomersController> >(),
                                                     testLogger);

            // Set mock HTTP context (including DI service provider)
            controller.ControllerContext.HttpContext = new DefaultHttpContext()
            {
                RequestServices = _serviceProvider
            };

            return(controller);
        }