This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from stoveproject/dev
dev to master
- Loading branch information
Showing
60 changed files
with
2,296 additions
and
1,424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Stove.Couchbase/Couchbase/Configuration/IStoveCouchbaseConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Stove.Couchbase/Couchbase/Configuration/StoveCouchbaseConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Stove.Couchbase/Couchbase/Configuration/StoveCouchbaseConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Stove.Couchbase/Couchbase/Filters/Action/CouchbaseActionFilterExecuter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Stove.Couchbase/Couchbase/Filters/Action/ICouchbaseActionFilterExecuter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Stove.Couchbase/Couchbase/Filters/Action/NullCouchbaseActionFilterExecuter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/Stove.Couchbase/Couchbase/Repositories/CouchbaseRepositoryBaseOfTEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
src/Stove.Couchbase/Couchbase/StoveCouchbaseBootstrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Stove.Couchbase/Couchbase/StoveCouchbaseRegistrationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.