public UserUnitTest() { var unitOfWork = IoCUtility.Resolve <IUnitOfWork <DbContext> >(); var repositoryFactory = IoCUtility.Resolve <IRepositoryFactory>(); _userService = new UserService(unitOfWork, repositoryFactory); }
public AuthenticationsController() { var unitOfWork = IoCUtility.Resolve <IUnitOfWork <DbContext> >(); var repositoryFactory = IoCUtility.Resolve <IRepositoryFactory>(); _userService = new UserService(unitOfWork, repositoryFactory); }
public ToDoListsController() { var unitOfWork = IoCUtility.Resolve <IUnitOfWork <DbContext> >(); var repositoryFactory = IoCUtility.Resolve <IRepositoryFactory>(); _toDoListService = new ToDoListService(unitOfWork, repositoryFactory); }
private void RegisterInterfaces() { IUnityContainer unityContainer = IoCUtility.GetInstance(); unityContainer.RegisterType(typeof(IProcessMsg), typeof(ProcessMsg)); unityContainer.RegisterType(typeof(IManagerMsg), typeof(ManagerMsg)); }
public SensorController() { this._unityContainer = IoCUtility.GetInstance(); this.ProcessMsg = _unityContainer.Resolve <IProcessMsg>(); this.ManagerMsg = _unityContainer.Resolve <IManagerMsg>(); }
public NotificationSender() { var unitOfWork = IoCUtility.Resolve <IUnitOfWork <DbContext> >("isolatedUnitOfWork"); var repositoryFactory = IoCUtility.Resolve <IRepositoryFactory>("isolatedRepositoryFactory"); _toDoListService = new ToDoListService(unitOfWork, repositoryFactory); _taskService = new TaskService(unitOfWork, repositoryFactory); }
public void GetInterfaceAndClassFromAssemblyTest() { var interfaceClassPaires = IoCUtility.GetInterfaceAndClass( "Evol.FirstEC.Domain.Repositories" , "Evol.FirstEC.Data.Repositories" , Assembly.Load("Evol.FirstEC.Domain") , Assembly.Load("Evol.FirstEC.Data") ); interfaceClassPaires.ForEach(p => Trace.WriteLine(p.Interface.FullName + "\r\n : " + p.Impl.FullName)); }
public IHttpActionResult Post(AuditLogItemContract auditLogContract) { Task.Run(() => { var auditLogService = IoCUtility.Resolve <IAuditLogService>(); var mappedEntity = Mapper.Map <AuditLogItemContract, AuditLogItem <int, object> >(auditLogContract); auditLogService.Save("WebSiteExceptionHandler", mappedEntity); }); return(Ok()); }
private void SendNotifications(List <NotificationItemContract> notificationItems) { var mailNotificationService = IoCUtility.Resolve <INotificationService>(); foreach (var notificationItem in notificationItems) { string bodyMessage = string.Format("Hi {0}, <br/>This notification for: {1}", notificationItem.FullName, notificationItem.Title); mailNotificationService.SendNotification( ConfigurationManager.AppSettings["NotificationFromMail"], notificationItem.Email, ConfigurationManager.AppSettings["NotificationMailSubject"], bodyMessage ); } }
private void ReportError(HttpActionExecutedContext actionExecutedContext) { Exception exception = actionExecutedContext.Exception; Task.Run(() => { var auditLogService = IoCUtility.Resolve <IAuditLogService>(); auditLogService.Save("ApiExceptionHandler", new AuditLogItem <int, object> { Action = actionExecutedContext.Request.RequestUri.PathAndQuery, Message = exception.Message, Entity = exception }); }); }
public void RegisterQueryEntry(string interfaceNamespace, string classNamespace, params Assembly[] assemblies) { if (string.IsNullOrWhiteSpace(interfaceNamespace)) { throw new ArgumentNullException(nameof(interfaceNamespace)); } if (string.IsNullOrWhiteSpace(classNamespace)) { throw new ArgumentNullException(nameof(classNamespace)); } if (assemblies.Length == 0) { throw new ArgumentOutOfRangeException(nameof(assemblies) + "数组为空"); } var interfaceClassPaires = IoCUtility.GetInterfaceAndClass(interfaceNamespace, classNamespace, assemblies); interfaceClassPaires.ForEach(p => UnityContainer.RegisterType(p.Interface, p.Impl, new PerThreadLifetimeManager())); }
/// <summary> /// When in doubt, just use as it is, without setting anything yourself /// </summary> /// <param name="assembliesToScan">The assemblies containing Interfaces/Implementations</param> /// <param name="container">The Simple Injector container</param> public BaseContainer(string[] assembliesToScan = null, Container container = null) { if (container == null) { container = new Container(); } var assemblies = IoCUtility.GetAssembliesForRegistration("MultiTenancyFramework.SimpleInjector", assembliesToScan); container.Register(typeof(ICommandHandler <>), assemblies); container.Register(typeof(IDbQueryHandler <,>), assemblies); var exportedTypes = assemblies.SelectMany(x => x.ExportedTypes).Where(x => !x.IsAbstract); #region Known Cases. This part is made necessary due to a limitation of Simple Injector var types = exportedTypes.Where(x => x.IsGenericType && x.Name.StartsWith("CoreDAO")).ToArray(); if (types.Any(x => x.Name.EndsWith("2"))) { container.Register(typeof(ICoreDAO <,>), types.First(x => x.Name.EndsWith("2"))); } if (types.Any(x => x.Name.EndsWith("1"))) { container.Register(typeof(ICoreDAO <>), types.First(x => x.Name.EndsWith("1"))); } types = exportedTypes.Where(x => x.IsGenericType && x.Name.StartsWith("PrivilegeDAO")).ToArray(); if (types.Any(x => x.Name.EndsWith("1"))) { container.Register(typeof(IPrivilegeDAO <>), types.First(x => x.Name.EndsWith("1"))); } types = exportedTypes.Where(x => x.IsGenericType && x.Name.StartsWith("AppUserDAO")).ToArray(); if (types.Any(x => x.Name.EndsWith("1"))) { container.Register(typeof(IAppUserDAO <>), types.First(x => x.Name.EndsWith("1"))); } types = exportedTypes.Where(x => x.IsGenericType && x.Name.StartsWith("InstitutionDAO")).ToArray(); if (types.Any(x => x.Name.EndsWith("1"))) { container.Register(typeof(IInstitutionDAO <>), types.First(x => x.Name.EndsWith("1"))); } #endregion // This is for convention-based registrations. Convention is IService/Service var registrations = from type in exportedTypes //where !type.IsAbstract where !type.IsGenericType where type.GetInterfaces().Any(x => x.Name.EndsWith(type.Name)) select new { Service = type.GetInterfaces().Single(x => x.Name.EndsWith(type.Name)), Implementation = type } ; registrations = registrations.ToArray(); foreach (var reg in registrations) { container.Register(reg.Service, reg.Implementation); } // Cache Manager container.Register <ICacheManager, MemoryCacheManager>(Lifestyle.Singleton); // Finally... container.Register(typeof(IServiceProvider), () => container); Container = container; }
public LogUnitTest() { _auditLogService = IoCUtility.Resolve <IAuditLogService>(); }