Beispiel #1
0
        public T Repository <T>() where T : class, IUnitOfWorkRepository
        {
            Type typeT = typeof(T);

            Type typeRepositorio = null;

            if (typeT.IsGenericType)
            {
                Type typeRepositorioGeneric = typeof(BaseRepository <,>);
                typeRepositorio = typeRepositorioGeneric.MakeGenericType(typeT.GetGenericArguments());
            }

            if ((_repositoryConfig != null) && (_repositoryConfig.HasInterfaceBind(typeT)))
            {
                typeRepositorio = _repositoryConfig.GetConcreteBind(typeT);
            }

            if (typeRepositorio == null)
            {
                throw new ArgumentNullException(typeof(T).ToString() + " not implements bind");
            }

            if (!typeRepositorio.IsSubclassOf(typeof(UnitOfWorkRepository)))
            {
                throw new NotSupportedException(typeRepositorio.ToString() + " not implements " + typeof(UnitOfWorkRepository).ToString());
            }

            var repositorio = Activator.CreateInstance(typeRepositorio);

            ((UnitOfWorkRepository)repositorio).SetUnitOfWorkContext(Context);

            return((T)repositorio);
        }