private static UnitOfWorkFactory CreateUnitOfWorkFactory(UnitOfWorkType type) { switch (type) { case UnitOfWorkType.Database: return(new DatabaseUnitOfWorkFactory()); } throw new ArgumentException("Unit of work factory for type " + type + " is not implemented. Check the switch in HaaSMiddleware.DataAccessLayer.Factory.UnitOfWork.AbstractUnitOfWorkFactory.CreateUnitOfWorkFactory(UnitOfWorkType type) method."); }
public static UnitOfWorkFactory GetUnitOfWorkFactory(UnitOfWorkType type) { lock (_factoryInstances) { if (!_factoryInstances.ContainsKey(type)) { _factoryInstances.Add(type, CreateUnitOfWorkFactory(type)); } } return(_factoryInstances[type]); }
public IUnitOfWork Create <TContext>(UnitOfWorkType unitOfWorkType) where TContext : DbContext { var constructorInfo = typeof(TContext).GetConstructor(new Type[] {}); if (constructorInfo == null) { throw new TargetParameterCountException("Cannot generically create a DbContext with constructor parameters"); } var dbContext = constructorInfo.Invoke(new object[] {}) as TContext; return(unitOfWorkType == UnitOfWorkType.Persistent ? new PersistenceManager <TContext>(dbContext) : new TransactionManager <TContext>() as IUnitOfWork); }