Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #98 from stoveproject/dev
Browse files Browse the repository at this point in the history
dev to master
  • Loading branch information
osoykan authored Oct 16, 2017
2 parents d9548a7 + efff0df commit 1600bb4
Show file tree
Hide file tree
Showing 60 changed files with 2,296 additions and 1,424 deletions.
16 changes: 15 additions & 1 deletion Stove.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{4D2BAE52-1E23-4321-BBE6-2BAC28F7B389}"
EndProject
Expand Down Expand Up @@ -86,6 +86,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stove.Serilog", "src\Stove.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stove.Serilog.Tests", "test\Stove.Serilog.Tests\Stove.Serilog.Tests.csproj", "{38E61EC8-F69C-41B1-9356-F5FD6DA507F0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stove.Couchbase", "src\Stove.Couchbase\Stove.Couchbase.csproj", "{3AFF2B60-62F5-4547-9152-DD26E1A9918A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stove.Couchbase.Tests", "test\Stove.Couchbase.Tests\Stove.Couchbase.Tests.csproj", "{46E3FC0A-20B8-4749-AA68-1D165249211C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -224,6 +228,14 @@ Global
{38E61EC8-F69C-41B1-9356-F5FD6DA507F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38E61EC8-F69C-41B1-9356-F5FD6DA507F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38E61EC8-F69C-41B1-9356-F5FD6DA507F0}.Release|Any CPU.Build.0 = Release|Any CPU
{3AFF2B60-62F5-4547-9152-DD26E1A9918A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AFF2B60-62F5-4547-9152-DD26E1A9918A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AFF2B60-62F5-4547-9152-DD26E1A9918A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AFF2B60-62F5-4547-9152-DD26E1A9918A}.Release|Any CPU.Build.0 = Release|Any CPU
{46E3FC0A-20B8-4749-AA68-1D165249211C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46E3FC0A-20B8-4749-AA68-1D165249211C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46E3FC0A-20B8-4749-AA68-1D165249211C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46E3FC0A-20B8-4749-AA68-1D165249211C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -263,6 +275,8 @@ Global
{03D9983F-C710-4765-8AE3-06C178E0C6BF} = {0EDEEA26-64C8-4391-9991-96E25131D4C6}
{59590481-E87E-418F-B5D8-8C415FF4B027} = {23CB5044-8ECE-4DDC-89E0-FC1B8EC9DDDF}
{38E61EC8-F69C-41B1-9356-F5FD6DA507F0} = {4D2BAE52-1E23-4321-BBE6-2BAC28F7B389}
{3AFF2B60-62F5-4547-9152-DD26E1A9918A} = {23CB5044-8ECE-4DDC-89E0-FC1B8EC9DDDF}
{46E3FC0A-20B8-4749-AA68-1D165249211C} = {4D2BAE52-1E23-4321-BBE6-2BAC28F7B389}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FA9941D3-2A68-4501-B951-D2447D6EF432}
Expand Down
4 changes: 2 additions & 2 deletions common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>2.0.7</VersionPrefix>
<VersionPrefix>2.0.8</VersionPrefix>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<PackageIconUrl>https://raw.githubusercontent.com/osoykan/Stove/master/stove.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/osoykan/Stove</PackageProjectUrl>
Expand All @@ -22,6 +22,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.4.0" PrivateAssets="All" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.5.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Couchbase.Configuration.Client;

namespace Stove.Couchbase.Configuration
{
public interface IStoveCouchbaseConfiguration
{
ClientConfiguration ClientConfiguration { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Autofac.Extras.IocManager;

using Couchbase.Configuration.Client;

namespace Stove.Couchbase.Configuration
{
public class StoveCouchbaseConfiguration : IStoveCouchbaseConfiguration, ISingletonDependency
{
public StoveCouchbaseConfiguration()
{
ClientConfiguration = new ClientConfiguration();
}

public ClientConfiguration ClientConfiguration { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Stove.Configuration;

namespace Stove.Couchbase.Configuration
{
public static class StoveCouchbaseConfigurationExtensions
{
public static IStoveCouchbaseConfiguration StoveCouchbase(this IModuleConfigurations modules)
{
return modules.StoveConfiguration.Get<IStoveCouchbaseConfiguration>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Autofac.Extras.IocManager;

using Stove.Domain.Entities;
using Stove.Domain.Uow.DynamicFilters.Action;

namespace Stove.Couchbase.Filters.Action
{
public class CouchbaseActionFilterExecuter : ICouchbaseActionFilterExecuter, ITransientDependency
{
private readonly IScopeResolver _scopeResolver;

public CouchbaseActionFilterExecuter(IScopeResolver scopeResolver)
{
_scopeResolver = scopeResolver;
}

public void ExecuteCreationAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>
{
_scopeResolver.Resolve<CreationAuditActionFilter>().ExecuteFilter<TEntity, TPrimaryKey>(entity);
}

public void ExecuteModificationAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>
{
_scopeResolver.Resolve<ModificationAuditActionFilter>().ExecuteFilter<TEntity, TPrimaryKey>(entity);
}

public void ExecuteDeletionAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>
{
_scopeResolver.Resolve<DeletionAuditActionFilter>().ExecuteFilter<TEntity, TPrimaryKey>(entity);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Stove.Domain.Entities;

namespace Stove.Couchbase.Filters.Action
{
public interface ICouchbaseActionFilterExecuter
{
void ExecuteCreationAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>;

void ExecuteModificationAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>;

void ExecuteDeletionAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Stove.Domain.Entities;

namespace Stove.Couchbase.Filters.Action
{
public class NullCouchbaseActionFilterExecuter : ICouchbaseActionFilterExecuter
{
public static NullCouchbaseActionFilterExecuter Instance = new NullCouchbaseActionFilterExecuter();

public void ExecuteCreationAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>
{
}

public void ExecuteModificationAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>
{
}

public void ExecuteDeletionAuditFilter<TEntity, TPrimaryKey>(TEntity entity) where TEntity : class, IEntity<TPrimaryKey>
{
}
}
}
9 changes: 9 additions & 0 deletions src/Stove.Couchbase/Couchbase/ISessionProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Couchbase.Linq;

namespace Stove.Couchbase
{
public interface ISessionProvider
{
IBucketContext Session { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System.Linq;

using Couchbase;
using Couchbase.Linq;

using Stove.Couchbase.Filters.Action;
using Stove.Domain.Entities;
using Stove.Domain.Repositories;
using Stove.Events.Bus.Entities;

namespace Stove.Couchbase.Repositories
{
public class CouchbaseRepositoryBase<TEntity> : StoveRepositoryBase<TEntity, string> where TEntity : class, IEntity<string>
{
private readonly ISessionProvider _sessionProvider;

public CouchbaseRepositoryBase(
ISessionProvider sessionProvider)
{
_sessionProvider = sessionProvider;

GuidGenerator = SequentialGuidGenerator.Instance;
EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
ActionFilterExecuter = NullCouchbaseActionFilterExecuter.Instance;
}

public ICouchbaseActionFilterExecuter ActionFilterExecuter { get; set; }

public IEntityChangeEventHelper EntityChangeEventHelper { get; set; }

public IGuidGenerator GuidGenerator { get; set; }

public IBucketContext Session => _sessionProvider.Session;

public override IQueryable<TEntity> GetAll()
{
return Session.Query<TEntity>();
}

public override TEntity Insert(TEntity entity)
{
entity.Id = GuidGenerator.Create().ToString("N");
ActionFilterExecuter.ExecuteCreationAuditFilter<TEntity, string>(entity);

EntityChangeEventHelper.TriggerEntityCreatingEvent(entity);

IDocumentResult<TEntity> result = Session.Bucket.Insert(new Document<TEntity>
{
Content = entity,
Id = $"{typeof(TEntity).Name}:{entity.Id}"
});

result.EnsureSuccess();

EntityChangeEventHelper.TriggerEntityCreatedEventOnUowCompleted(entity);

return result.Content;
}

public override TEntity Update(TEntity entity)
{
ActionFilterExecuter.ExecuteModificationAuditFilter<TEntity, string>(entity);

EntityChangeEventHelper.TriggerEntityUpdatingEvent(entity);

IDocumentResult<TEntity> result = Session.Bucket.Upsert(new Document<TEntity>
{
Content = entity,
Id = $"{typeof(TEntity).Name}:{entity.Id}"
});

result.EnsureSuccess();

EntityChangeEventHelper.TriggerEntityUpdatedEventOnUowCompleted(entity);

return result.Content;
}

public override void Delete(TEntity entity)
{
ActionFilterExecuter.ExecuteDeletionAuditFilter<TEntity, string>(entity);

EntityChangeEventHelper.TriggerEntityDeletingEvent(entity);

if (entity is ISoftDelete)
{
Session.Bucket.Upsert(new Document<TEntity>
{
Content = entity,
Id = $"{typeof(TEntity).Name}:{entity.Id}"
}).EnsureSuccess();
}
else
{
Session.Bucket.Remove(new Document<TEntity>
{
Content = entity,
Id = $"{typeof(TEntity).Name}:{entity.Id}"
}).EnsureSuccess();
}

EntityChangeEventHelper.TriggerEntityDeletedEventOnUowCompleted(entity);
}

public override void Delete(string id)
{
Session.Bucket.Remove(id).EnsureSuccess();
}
}
}
20 changes: 20 additions & 0 deletions src/Stove.Couchbase/Couchbase/StoveCouchbaseBootstrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Couchbase.Core;

using Stove.Bootstrapping;
using Stove.Couchbase.Configuration;

namespace Stove.Couchbase
{
public class StoveCouchbaseBootstrapper : StoveBootstrapper
{
public override void PreStart()
{
StoveConfiguration.GetConfigurerIfExists<IStoveCouchbaseConfiguration>()(StoveConfiguration.Modules.StoveCouchbase());
}

public override void Shutdown()
{
Resolver.Resolve<ICluster>().Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

using Autofac;
using Autofac.Extras.IocManager;

using Couchbase;
using Couchbase.Core;

using Stove.Couchbase.Configuration;
using Stove.Couchbase.Repositories;
using Stove.Domain.Repositories;
using Stove.Reflection.Extensions;

namespace Stove.Couchbase
{
public static class StoveCouchbaseRegistrationExtensions
{
public static IIocBuilder UseStoveCouchbase(this IIocBuilder builder, Func<IStoveCouchbaseConfiguration, IStoveCouchbaseConfiguration> configurer)
{
return builder
.RegisterServices(r =>
{
r.UseBuilder(cb =>
{
cb.RegisterGeneric(typeof(CouchbaseRepositoryBase<>)).As(typeof(IRepository<,>)).PropertiesAutowired();
});
r.Register(ctx => configurer);
r.Register<ICluster>(ctx =>
{
var cfg = ctx.Resolver.Resolve<IStoveCouchbaseConfiguration>();

return new Cluster(cfg.ClientConfiguration);
}, Lifetime.Singleton);

r.RegisterAssemblyByConvention(typeof(StoveCouchbaseRegistrationExtensions).GetAssembly());
});
}
}
}
Loading

0 comments on commit 1600bb4

Please sign in to comment.