using System; using System.Collections.Generic; namespace EPS.Common.Repositories { /// /// Responsible for maintaining active repositories through the life of an application. /// public static class RepoFactory { private static Dictionary _repos = new Dictionary(); /// /// Deletes the repository for the type of TModel. /// /// The type of the model. public static void Delete() where TModel : IModel, new() { _repos.Remove(GetKey()); } /// /// Gets a repository for the type of TModel. If one does not already exist, it will /// be created and returned, otherwise the existing one is returned. /// /// The type of the model used as the type of the repository /// to create or retrieve. /// A repository for the specified type. public static IRepository Get() where TModel : IModel, new() { string key = GetKey(); if (_repos.ContainsKey(key)) return (IRepository)_repos[key]; IRepository repo = new Repository(); _repos.Add(key, repo); return repo; } private static string GetKey() { return typeof(TModel).Name; } } }