109
using KCS.DataAccess.Context;
using KCS.DataAccess.Interfaces;
using KCS.DataAccess.Repositories;
using System;
using System.Collections.Generic;
namespace KCS.DataAccess
{
/// <summary>
/// Реализует интерфейс хранилища объединяющий в себе репозитории для
работы с данными.
/// </summary>
public class Storage : IStorage
{
public Storage(KCSContext kcsContext) => this.kcsContext = kcsContext;
private readonly KCSContext kcsContext;
private Dictionary<string, object> repositories;
private MixedRepository mixedRepository;
public GenericRepository<TEntity> GetRepository<TEntity>() where TEntity :
class
{
if (repositories == null)
repositories = new Dictionary<string, object>();
string type = typeof(TEntity).Name;
if (!repositories.ContainsKey(type))
{
Type repositoryType = typeof(GenericRepository<>);
object repositoryInstance =
Activator.CreateInstance(repositoryType.MakeGenericType(typeof(TEntity)),
kcsContext);
repositories.Add(type, repositoryInstance);
}
return (GenericRepository<TEntity>)repositories[type];
}
public MixedRepository MixedRepository
{
get
{