コード例 #1
0
ファイル: Storage.cs プロジェクト: crazyants/ExtCore
        public TRepository GetRepository <TRepository>() where TRepository : IRepository
        {
            TRepository repository = ExtensionManager.GetInstance <TRepository>(a => a.FullName.ToLower().Contains("entityframework.postgresql"));

            repository.SetStorageContext(this.StorageContext);
            return(repository);
        }
コード例 #2
0
ファイル: Storage.cs プロジェクト: tomtangrx/ExtCore
        /// <summary>
        /// Gets a repository of the given type.
        /// </summary>
        /// <typeparam name="T">The type parameter to find implementation of.</typeparam>
        /// <returns></returns>
        public TRepository GetRepository <TRepository>() where TRepository : IRepository
        {
            TRepository repository = ExtensionManager.GetInstance <TRepository>();

            repository.SetStorageContext(this.StorageContext);
            return(repository);
        }
コード例 #3
0
ファイル: Storage.cs プロジェクト: Benriya-Tech/ExtCore
        /// <summary>
        /// Gets a repository of the given type.
        /// </summary>
        /// <typeparam name="T">The type parameter to find implementation of.</typeparam>
        /// <returns></returns>
        public TRepository GetRepository <TRepository>() where TRepository : IRepository
        {
            TRepository repository = ExtensionManager.GetInstance <TRepository>();

            if (repository != null)
            {
                repository.SetStorageContext(this.StorageContext, this.Client);
            }

            return(repository);
        }
コード例 #4
0
        public TRepository GetRepository <TRepository>() where TRepository : IRepository
        {
            foreach (Type type in this.GetType().GetTypeInfo().Assembly.GetTypes())
            {
                if (typeof(TRepository).GetTypeInfo().IsAssignableFrom(type) && type.GetTypeInfo().IsClass)
                {
                    TRepository repository = (TRepository)Activator.CreateInstance(type);

                    repository.SetStorageContext(this.Context);
                    return(repository);
                }
            }

            return(default(TRepository));
        }
コード例 #5
0
        public TRepository GetRepository <TRepository>() where TRepository : IDataRepository
        {
            foreach (Assembly assembly in Assemblies.Where(a => !a.FullName.Contains("Reflection")))
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (typeof(TRepository).IsAssignableFrom(type) && type.GetTypeInfo().IsClass)
                    {
                        TRepository repository = (TRepository)Activator.CreateInstance(type);
                        repository.SetStorageContext(StorageContext);
                        return(repository);
                    }
                }
            }

            throw new ArgumentException("Implementation of " + typeof(TRepository) + " not found");
        }