Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Samhammer.Mongo/BaseRepositoryMongo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
Expand All @@ -12,19 +13,23 @@ public class BaseRepositoryMongo<T> : IBaseRepositoryMongo<T>
{
protected ILogger<BaseRepositoryMongo<T>> Logger { get; }

protected IMongoCollection<T> Collection { get; }
protected IMongoCollection<T> Collection => collection.Value;

private IMongoDatabase Database { get; }
private IMongoDatabase Database => database.Value;

protected FilterDefinitionBuilder<T> Filter => Builders<T>.Filter;

protected UpdateDefinitionBuilder<T> Update => Builders<T>.Update;


private readonly Lazy<IMongoCollection<T>> collection;

private readonly Lazy<IMongoDatabase> database;

public BaseRepositoryMongo(ILogger<BaseRepositoryMongo<T>> logger, IMongoDbConnector connector, string databaseName = null)
{
Logger = logger;
Database = connector.GetMongoDatabase(databaseName);
Collection = GetCollection<T>();
database = new Lazy<IMongoDatabase>(() => connector.GetMongoDatabase(databaseName));
collection = new Lazy<IMongoCollection<T>>(GetCollection<T>);
}

protected IMongoCollection<TR> GetCollection<TR>()
Expand Down
2 changes: 2 additions & 0 deletions src/Samhammer.MongoDb.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" WarnAboutPrefixesAndSuffixes="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String></wpf:ResourceDictionary>