public BaseRepository(IDbService dbService) { // TODO: Check if the client object can be made static, and avoid many open and closures. db = dbService.GetDatabase(); MongoClient = dbService.GetClient(); this.CollectionName = CollectionNameAttribute.GetCollectionName <T>(); this.Collection = GetCollection(); this.QuerableCollection = this.Collection.AsQueryable <T>(); }
public static string GetCollectionNameFromType <T>() { Type type = typeof(T); string collectionName = null; CollectionNameAttribute collectionNameAttribute = Attribute.GetCustomAttribute(type, typeof(CollectionNameAttribute)) as CollectionNameAttribute; if (collectionNameAttribute != null) { collectionName = collectionNameAttribute.CollectionName; } else { collectionName = type.Name; } return(collectionName); }
public VersionMongoRepository(IConnect connect, string collectionName = null, ISnapshotFreqPolicy snapshotFreqPolicy = null) { this.Connect = connect; if (string.IsNullOrEmpty(collectionName)) { CollectionNameAttribute mongoCollectionName = (CollectionNameAttribute)typeof(T).GetTypeInfo().GetCustomAttribute(typeof(CollectionNameAttribute)); this.CollectionName = (mongoCollectionName != null ? mongoCollectionName.Name : typeof(T).Name.ToLower()); mongoCollectionName = null; } else { this.CollectionName = collectionName; } this.OriginalCollection = this.Connect.Collection <T>(this.CollectionName); this.SnapshotFreqPolicy = snapshotFreqPolicy ?? new SnapshotFreqPolicy.MonthSnapshot(); }
public void CollectionNameAttribute_Tests() { CollectionNameAttribute attribute = new CollectionNameAttribute("value"); var value = attribute.Name; }