/// <inheritdoc /> public IRepository <TEntity> GetRepository <TEntity>() where TEntity : class { Type entityType = typeof(TEntity); if (Repositories.ContainsKey(entityType)) { Logger?.LogDebug($"Get existing Repository for entity {typeof(TEntity).Name}"); return((IRepository <TEntity>)Repositories[entityType]); } try { Logger?.LogDebug($"Get Repository for entity {typeof(TEntity).Name} from services"); IRepository <TEntity> customRepo = (IRepository <TEntity>)_serviceProvider.GetService(typeof(IRepository <TEntity>)); Repositories[entityType] = customRepo ?? throw new Exception("Service null"); return(customRepo); } catch (Exception e) { Logger?.LogDebug("Can't get Repository from service provider: {0}", e.Message); } Logger?.LogDebug($"Creating new Repository for entity {typeof(TEntity).Name}"); Repositories[entityType] = new Repository <TEntity>(DbContext); return((IRepository <TEntity>)Repositories[entityType]); }
/// <summary> /// Repositories this instance. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <returns></returns> public IRepository <TEntity> Repository <TEntity>() where TEntity : class, IEntity { if (_repositories == null) { _repositories = new Hashtable(); } var typeName = typeof(TEntity).Name; var keyType = typeof(TEntity); if (Repositories.ContainsKey(keyType)) { return((IRepository <TEntity>)_repositories[typeName]); } else { var instance = _serviceProvider.GetService(typeof(TEntity)); var instanceType = instance.GetType(); var setMethod = GetType().GetTypeInfo() .GetMethod("CreateRepository").MakeGenericMethod(typeof(TEntity), instanceType); var repository = (IRepository <TEntity>)setMethod.Invoke(this, new object[] { }); Repositories[keyType] = repository; return(repository); } }
/// <summary> /// Registra un proveedor de un repositorio para un tipo /// </summary> public void Register(string strKey, IProviderRepository objRepository) { if (!Repositories.ContainsKey(strKey)) { Repositories.Add(strKey, objRepository); } }
public T Repository <T>() where T : class { var type = typeof(T); if (!Repositories.ContainsKey(type)) { Repositories.Add(type, DbUtil.Repository <T>(this)); } return(Repositories[type]); }
public IRepository <T> Repository <T>() where T : EntityBase { var type = typeof(T); if (!Repositories.ContainsKey(type)) { Repositories.Add(type, new Repository <T>(DbContext)); } return(Repositories[type]); }
public IRepository <TEntity> GetRepository <TEntity>() where TEntity : class { var type = typeof(TEntity); if (!Repositories.ContainsKey(type)) { Repositories.Add(type, new Repository <TEntity>(this)); } return(Repositories[type] as IRepository <TEntity>); }
/// <summary> /// Obtiene un nuevo proveedor de repositorio para la clave definida /// </summary> public IProviderRepository GetInstance(string strKey) { if (Repositories.ContainsKey(strKey)) { return(Repositories[strKey].GetInstance()); } else { return(null); } }
public IRepository <TEntity> Repository <TEntity>() where TEntity : class { var type = typeof(TEntity).Name; if (Repositories.ContainsKey(type)) { return((IRepository <TEntity>)Repositories[type]); } Repositories.Add(type, new Repository <TEntity>(Context)); return(Repositories[type]); }
public IRepository <TEntity> GetRepository <TEntity>() where TEntity : class { if (Repositories == null) { Repositories = new Dictionary <Type, Object>(); } var type = typeof(TEntity); if (!Repositories.ContainsKey(type)) { Repositories[type] = new Repository <TEntity>(DbContext); } return((IRepository <TEntity>)Repositories[type]); }
/// <summary>Make a repository of type T.</summary> /// <typeparam name="T">Type of repository to make.</typeparam> /// <param name="dbContext"> /// The <see cref="DbContext"/> with which to initialize the repository. /// </param> /// <param name="factory"> /// Factory with <see cref="DbContext"/> argument. Used to make the repository. /// If null, gets factory from <see cref="_repositoryFactories"/>. /// </param> /// <returns></returns> protected virtual T MakeRepository <T>(Func <DbContext, object> factory, DbContext dbContext) { var f = factory ?? _repositoryFactories.GetRepositoryFactory <T>(); if (f == null) { throw new NotImplementedException("No factory for repository type, " + typeof(T).FullName); } var repo = (T)f(dbContext); if (!Repositories.ContainsKey(typeof(T))) { Repositories[typeof(T)] = repo; } return(repo); }
public TRepository GetRepository <TRepository, T>() where TRepository : class, IRepository <T> where T : class { if (Repositories == null) { Repositories = new Dictionary <Type, object>(); } var type = typeof(T); if (!Repositories.ContainsKey(type)) { Repositories[type] = InitRepository <TRepository, T>(); } return((TRepository)Repositories[type]); }
public override IRepositoryAsync <TEntity> RepositoryAsync <TEntity>() { if (Repositories == null) { Repositories = new Dictionary <string, dynamic>(); } var type = typeof(TEntity).Name; if (Repositories.ContainsKey(type)) { return((IRepositoryAsync <TEntity>)Repositories[type]); } // Add fake repository var repositoryType = typeof(FakeRepository <>); Repositories.Add(type, Activator.CreateInstance(repositoryType.MakeGenericType(typeof(TEntity)), _context, this)); return(Repositories[type]); }
/* Create GitTasks for all repositories in the Properties file * Update their TaskLists * Should only be done when necessary */ public bool AddRepositories() { foreach (RepoDetails repo in Properties.Repositories) { if (!Repositories.ContainsKey(repo.Name)) { try { Repositories.Add(repo.Name, new GitTask(Properties.Author, repo.Name, repo.Path)); } catch (Exception e) { Console.WriteLine(e.Message); } } } foreach (GitTask t in Repositories.Values) { t.ReadUpdates(Properties.UpdateCount); } return(true); }
private Dictionary <string, List <Package> > InitPackages(List <DeploymentFile> deploymentFiles) { var packagesDict = new Dictionary <string, Dictionary <string, Package> >(); foreach (var deploymentFile in deploymentFiles) { if (deploymentFile.Packages == null) { continue; } foreach (var filePackage in deploymentFile.Packages) { if (string.IsNullOrEmpty(filePackage.Id)) { throw new InvalidDataException(string.Format("Missing package id in {0}", deploymentFile.FileName)); } if (string.IsNullOrEmpty(filePackage.Version)) { throw new InvalidDataException(string.Format("Missing package version in {0} for {1}", deploymentFile.FileName, filePackage.Id)); } if (string.IsNullOrEmpty(filePackage.SourceID)) { throw new InvalidDataException(string.Format("Missing package sourceId in {0} for {1}", deploymentFile.FileName, filePackage.Id)); } if (!Repositories.ContainsKey(filePackage.SourceID)) { throw new InvalidDataException(string.Format("sourceId {0} used by package {1}}", filePackage.SourceID, filePackage.Id)); } SemanticVersion semVer = Utils.ParseVersion(filePackage.Version); Package package = new Package(filePackage.Id, semVer, Repositories[filePackage.SourceID]); if (!packagesDict.ContainsKey(filePackage.Id)) { packagesDict[filePackage.Id] = new Dictionary <string, Package>(); } if (packagesDict[filePackage.Id].ContainsKey(filePackage.Id)) { Utils.Log("Overriding package {0} with the one on deployment file {1}", filePackage.Id, deploymentFile.FileName); } else { Utils.Log("Using package {0}", filePackage.Id); } packagesDict[filePackage.Id][filePackage.Id + "-" + filePackage.Version] = package; if (filePackage.Commands != null && filePackage.Commands.Length > 0) { var commandList = package.Commands; foreach (var fileCommand in filePackage.Commands) { string commandPath = Environment.ExpandEnvironmentVariables(fileCommand.FilePath);; if (!string.IsNullOrEmpty(commandPath) && !Path.IsPathRooted(commandPath)) { commandPath = Path.GetFullPath(Path.Combine(package.InstallPath, commandPath)); } commandList.Add(new Command(commandPath, fileCommand.Arguments, InitEnvVariables(fileCommand.EnvVariables))); } } } } var packages = new Dictionary <string, List <Package> >(); foreach (var entry in packagesDict) { var list = new List <Package>(entry.Value.Count); foreach (var packageEnty in entry.Value) { list.Add(packageEnty.Value); AddConfigMapping("package-" + packageEnty.Value.ToFullString(), packageEnty.Value.InstallPath); } list.Sort((a, b) => { return(b.Version.CompareTo(a.Version)); }); packages[entry.Key] = list; } return(packages); }