Skip to content

Commit

Permalink
Merge pull request #19 from Valeriy1991/dev
Browse files Browse the repository at this point in the history
Separate commands with and without results
  • Loading branch information
abakumov-v authored Mar 14, 2019
2 parents db1971d + 3a76112 commit f349336
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 44 deletions.
8 changes: 4 additions & 4 deletions CQRSlight.Db/Abstract/DbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CQRSlight.Db.Abstract
{
public abstract class DbCommand<TCommandContext, TResult> : ICommand<TCommandContext, TResult>
public abstract class DbCommand : ICommand
{
protected IDbExecutor DbExecutor { get; }

Expand All @@ -16,10 +16,10 @@ protected DbCommand(IDbExecutor dbExecutor)
DbExecutor = dbExecutor;
}

public abstract IOutcome<TResult> Execute(TCommandContext commandContext);
public abstract IOutcome Execute();
}

public abstract class DbCommand<TCommandContext> : ICommand<TCommandContext>
public abstract class DbCommand<TCommandRequest> : ICommand<TCommandRequest>
{
protected IDbExecutor DbExecutor { get; }

Expand All @@ -30,6 +30,6 @@ protected DbCommand(IDbExecutor dbExecutor)
DbExecutor = dbExecutor;
}

public abstract IOutcome Execute(TCommandContext commandContext);
public abstract IOutcome Execute(TCommandRequest commandRequest);
}
}
8 changes: 4 additions & 4 deletions CQRSlight.Db/Abstract/DbCommandAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CQRSlight.Db.Abstract
{
public abstract class DbCommandAsync<TCommandContext, TResult> : ICommandAsync<TCommandContext, TResult>
public abstract class DbCommandAsync : ICommandAsync
{
protected IDbExecutor DbExecutor { get; }

Expand All @@ -17,10 +17,10 @@ protected DbCommandAsync(IDbExecutor dbExecutor)
DbExecutor = dbExecutor;
}

public abstract Task<IOutcome<TResult>> ExecuteAsync(TCommandContext commandContext);
public abstract Task<IOutcome> ExecuteAsync();
}

public abstract class DbCommandAsync<TCommandContext> : ICommandAsync<TCommandContext>
public abstract class DbCommandAsync<TCommandRequest> : ICommandAsync<TCommandRequest>
{
protected IDbExecutor DbExecutor { get; }

Expand All @@ -31,6 +31,6 @@ protected DbCommandAsync(IDbExecutor dbExecutor)
DbExecutor = dbExecutor;
}

public abstract Task<IOutcome> ExecuteAsync(TCommandContext commandContext);
public abstract Task<IOutcome> ExecuteAsync(TCommandRequest commandRequest);
}
}
36 changes: 36 additions & 0 deletions CQRSlight.Db/Abstract/DbCommandWithResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using CQRSlight.Abstract;
using DbConn.DbExecutor.Abstract;
using Ether.Outcomes;

namespace CQRSlight.Db.Abstract
{
public abstract class DbCommandWithResult<TResult> : ICommandWithResult<TResult>
{
protected IDbExecutor DbExecutor { get; }

protected DbCommandWithResult(IDbExecutor dbExecutor)
{
if (dbExecutor == null)
throw new ArgumentNullException(nameof(dbExecutor));
DbExecutor = dbExecutor;
}

public abstract IOutcome<TResult> Execute();
}

public abstract class DbCommandWithResult<TCommandRequest, TResult> :
ICommandWithResult<TCommandRequest, TResult>
{
protected IDbExecutor DbExecutor { get; }

protected DbCommandWithResult(IDbExecutor dbExecutor)
{
if (dbExecutor == null)
throw new ArgumentNullException(nameof(dbExecutor));
DbExecutor = dbExecutor;
}

public abstract IOutcome<TResult> Execute(TCommandRequest commandRequest);
}
}
37 changes: 37 additions & 0 deletions CQRSlight.Db/Abstract/DbCommandWithResultAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Threading.Tasks;
using CQRSlight.Abstract;
using DbConn.DbExecutor.Abstract;
using Ether.Outcomes;

namespace CQRSlight.Db.Abstract
{
public abstract class DbCommandWithResultAsync<TResult> : ICommandWithResultAsync<TResult>
{
protected IDbExecutor DbExecutor { get; }

protected DbCommandWithResultAsync(IDbExecutor dbExecutor)
{
if (dbExecutor == null)
throw new ArgumentNullException(nameof(dbExecutor));
DbExecutor = dbExecutor;
}

public abstract Task<IOutcome<TResult>> ExecuteAsync();
}

public abstract class DbCommandWithResultAsync<TCommandRequest, TResult> :
ICommandWithResultAsync<TCommandRequest, TResult>
{
protected IDbExecutor DbExecutor { get; }

protected DbCommandWithResultAsync(IDbExecutor dbExecutor)
{
if (dbExecutor == null)
throw new ArgumentNullException(nameof(dbExecutor));
DbExecutor = dbExecutor;
}

public abstract Task<IOutcome<TResult>> ExecuteAsync(TCommandRequest commandRequest);
}
}
4 changes: 2 additions & 2 deletions CQRSlight.Db/Abstract/DbQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CQRSlight.Db.Abstract
{
public abstract class DbQuery<TContext, TResult> : IQuery<TContext, TResult>
public abstract class DbQuery<TRequest, TResult> : IQuery<TRequest, TResult>
{
protected IDbExecutor DbExecutor { get; }

Expand All @@ -15,7 +15,7 @@ protected DbQuery(IDbExecutor dbExecutor)
DbExecutor = dbExecutor;
}

public abstract TResult Get(TContext context);
public abstract TResult Get(TRequest request);
}

public abstract class DbQuery<TResult> : IQuery<TResult>
Expand Down
4 changes: 2 additions & 2 deletions CQRSlight.Db/Abstract/DbQueryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CQRSlight.Db.Abstract
{
public abstract class DbQueryAsync<TContext, TResult> : IQueryAsync<TContext, TResult>
public abstract class DbQueryAsync<TRequest, TResult> : IQueryAsync<TRequest, TResult>
{
protected IDbExecutor DbExecutor { get; }

Expand All @@ -16,7 +16,7 @@ protected DbQueryAsync(IDbExecutor dbExecutor)
DbExecutor = dbExecutor;
}

public abstract Task<TResult> GetAsync(TContext context);
public abstract Task<TResult> GetAsync(TRequest request);
}

public abstract class DbQueryAsync<TResult> : IQueryAsync<TResult>
Expand Down
9 changes: 5 additions & 4 deletions CQRSlight/Abstract/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace CQRSlight.Abstract
{
public interface ICommand<in TCommandContext, TResult>

public interface ICommand
{
IOutcome<TResult> Execute(TCommandContext commandContext);
IOutcome Execute();
}

public interface ICommand<in TCommandContext>
public interface ICommand<in TCommandRequest>
{
IOutcome Execute(TCommandContext commandContext);
IOutcome Execute(TCommandRequest commandRequest);
}
}
8 changes: 4 additions & 4 deletions CQRSlight/Abstract/ICommandAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace CQRSlight.Abstract
{
public interface ICommandAsync<in TCommandContext, TResult>
public interface ICommandAsync
{
Task<IOutcome<TResult>> ExecuteAsync(TCommandContext commandContext);
Task<IOutcome> ExecuteAsync();
}

public interface ICommandAsync<in TCommandContext>
public interface ICommandAsync<in TCommandRequest>
{
Task<IOutcome> ExecuteAsync(TCommandContext commandContext);
Task<IOutcome> ExecuteAsync(TCommandRequest commandRequest);
}
}
14 changes: 14 additions & 0 deletions CQRSlight/Abstract/ICommandWithResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Ether.Outcomes;

namespace CQRSlight.Abstract
{
public interface ICommandWithResult<TResult>
{
IOutcome<TResult> Execute();
}

public interface ICommandWithResult<in TCommandRequest, TResult>
{
IOutcome<TResult> Execute(TCommandRequest commandRequest);
}
}
15 changes: 15 additions & 0 deletions CQRSlight/Abstract/ICommandWithResultAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using Ether.Outcomes;

namespace CQRSlight.Abstract
{
public interface ICommandWithResultAsync<TResult>
{
Task<IOutcome<TResult>> ExecuteAsync();
}

public interface ICommandWithResultAsync<in TCommandRequest, TResult>
{
Task<IOutcome<TResult>> ExecuteAsync(TCommandRequest commandRequest);
}
}
4 changes: 2 additions & 2 deletions CQRSlight/Abstract/IQuery.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace CQRSlight.Abstract
{
public interface IQuery<in TContext, out TResult>
public interface IQuery<in TRequest, out TResult>
{
TResult Get(TContext context);
TResult Get(TRequest request);
}

public interface IQuery<out TResult>
Expand Down
4 changes: 2 additions & 2 deletions CQRSlight/Abstract/IQueryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace CQRSlight.Abstract
{
public interface IQueryAsync<in TContext, TResult>
public interface IQueryAsync<in TRequest, TResult>
{
Task<TResult> GetAsync(TContext context);
Task<TResult> GetAsync(TRequest request);
}

public interface IQueryAsync<TResult>
Expand Down
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ Install-Package CQRSlight.Db

#### CQRSlight

Contains 3 components:
Contains multiple main components:

1. IChecker
2. ICommand
3. IQuery
1. `IChecker`
2. `IQuery`
2. `ICommand`
2. `ICommandWithResult`

and it's async versions:

1. ICheckerAsync
2. ICommandAsync
3. IQueryAsync
1. `ICheckerAsync`
2. `IQueryAsync`
2. `ICommandAsync`
2. `ICommandWithResultAsync`

##### How to use

Expand All @@ -72,14 +74,14 @@ public class BlockedUserQuery : IQuery<List<User>>
```
3. Create your some `Command`:
```csharp
public class CreateUserCommand : ICommand<CreateUserCommandContext>
public class CreateUserCommand : ICommand<CreateUserCommandRequest>
{
private readonly PasswordHasher _passwordHasher = new PasswordHasher();

public IOutcome Execute(CreateUserCommandContext commandContext)
public IOutcome Execute(CreateUserCommandRequest commandRequest)
{
var email = commandContext.Email;
var password = commandContext.Password;
var email = commandRequest.Email;
var password = commandRequest.Password;

var passwordHash = _passwordHasher.GetHash(password);

Expand Down Expand Up @@ -116,17 +118,19 @@ public class CreatingUserEmailChecker : IChecker<User>

#### CQRSlight.Db

Contains 3 components:
Contains components:

1. DbChecker
2. DbQuery
3. DbCommand
1. `DbChecker`
2. `DbQuery`
2. `DbCommand`
2. `DbCommandWithResult`

and it's async versions:

1. DbCheckerAsync
2. DbQueryAsync
3. DbCommandAsync
1. `DbCheckerAsync`
2. `DbQueryAsync`
2. `DbCommandAsync`
2. `DbCommandWithResultAsync`

##### How to use

Expand Down Expand Up @@ -242,4 +246,4 @@ insert into dbo.UserAccount ...
}
}
}
```
```
2 changes: 1 addition & 1 deletion appveyor.master.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
version_suffix: alpha

version: 1.0.2-$(version_suffix){build}
version: 1.1.0-$(version_suffix){build}

# branches to build
branches:
Expand Down

0 comments on commit f349336

Please sign in to comment.