Skip to content

Commit

Permalink
Merge pull request #46 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Codespilot committed Dec 8, 2023
2 parents d668d0c + 6a69c89 commit 034f57a
Show file tree
Hide file tree
Showing 51 changed files with 858 additions and 492 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ resharper_move_local_function_after_jump_statement_highlighting = none;
resharper_move_local_function_after_jump_statement = false;
resharper_static_member_in_generic_type_highlighting = none;
resharper_virtual_member_call_in_constructor_highlighting = none;
resharper_inconsistently_synchronized_field_highlighting = hint;
resharper_inconsistently_synchronized_field_highlighting = hint;
resharper_redundant_type_declaration_body_highlighting = none;
resharper_separate_local_functions_with_jump_statement_highlighting = none;
resharper_convert_to_primary_constructor_highlighting = none;
18 changes: 9 additions & 9 deletions Source/Euonia.Application/ApplicationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace Nerosoft.Euonia.Application;
/// <inheritdoc />
public class ApplicationModule : ModuleContextBase
{
/// <inheritdoc />
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddTransient<IInterceptor, LoggingInterceptor>();
context.Services.AddTransient<IInterceptor, AuthorizationInterceptor>();
context.Services.AddTransient<IInterceptor, ValidationInterceptor>();
context.Services.AddTransient<IInterceptor, TracingInterceptor>();
context.Services.AddScoped<IRequestContextAccessor, DelegateRequestContextAccessor>();
}
/// <inheritdoc />
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddTransient<IInterceptor, LoggingInterceptor>();
context.Services.AddTransient<IInterceptor, AuthorizationInterceptor>();
context.Services.AddTransient<IInterceptor, ValidationInterceptor>();
context.Services.AddTransient<IInterceptor, TracingInterceptor>();
context.Services.AddScoped(typeof(IUseCasePresenter<>), typeof(DefaultUseCasePresenter<>));
}
}
11 changes: 4 additions & 7 deletions Source/Euonia.Application/Behaviors/BearerTokenBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Nerosoft.Euonia.Bus;
using Nerosoft.Euonia.Domain;
using Nerosoft.Euonia.Modularity;
using Nerosoft.Euonia.Pipeline;

namespace Nerosoft.Euonia.Application;
Expand Down Expand Up @@ -30,15 +31,11 @@ public BearerTokenBehavior(IRequestContextAccessor contextAccessor)
/// <inheritdoc />
public async Task<CommandResponse> HandleAsync(IRoutedMessage context, PipelineDelegate<IRoutedMessage, CommandResponse> next)
{
if (_contextAccessor?.RequestHeaders.TryGetValue("Authorization", out var values) == true)
if (_contextAccessor?.Context?.RequestHeaders.TryGetValue("Authorization", out var value) == true)
{
if (values.Count > 0)
if (!string.IsNullOrWhiteSpace(value) && value.StartsWith("Bearer") && !value.Equals("Bearer null", StringComparison.OrdinalIgnoreCase))
{
var value = values[0];
if (!string.IsNullOrWhiteSpace(value) && value.StartsWith("Bearer") && !value.Equals("Bearer null", StringComparison.OrdinalIgnoreCase))
{
context.Metadata.Set("$nerosoft:token", value);
}
context.Metadata.Set("$nerosoft:token", value);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using Castle.DynamicProxy;
using Microsoft.Extensions.Logging;
using Nerosoft.Euonia.Modularity;

namespace Nerosoft.Euonia.Application;

Expand Down
172 changes: 0 additions & 172 deletions Source/Euonia.Application/Seedwork/IRequestContextAccessor.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Nerosoft.Euonia.Bus;
using Nerosoft.Euonia.Claims;
using Nerosoft.Euonia.Modularity;

namespace Nerosoft.Euonia.Application;

Expand Down
52 changes: 52 additions & 0 deletions Source/Euonia.Application/UseCase/DefaultUseCasePresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Nerosoft.Euonia.Application;

/// <summary>
/// The default implementation of <see cref="IUseCasePresenter{TOutput}"/>.
/// </summary>
/// <typeparam name="TOutput"></typeparam>
public class DefaultUseCasePresenter<TOutput> : DisposableObject,
IUseCasePresenter<TOutput>
where TOutput : IUseCaseOutput
{
/// <inheritdoc/>
public event EventHandler<TOutput> OnSucceed;

/// <inheritdoc/>
public event EventHandler<Exception> OnFailed;

/// <inheritdoc/>
public event EventHandler OnCanceled;

/// <inheritdoc/>
public void Error(Exception exception)
{
if (exception is OperationCanceledException)
{
OnCanceled?.Invoke(this, EventArgs.Empty);
}
else
{
OnFailed?.Invoke(this, exception);
}
}

/// <inheritdoc/>
public void Ok(TOutput output)
{
Output = output;
OnSucceed?.Invoke(this, output);
}

/// <summary>
/// Gets the output of the use case.
/// </summary>
public TOutput Output { get; private set; }

/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
OnSucceed = null;
OnFailed = null;
OnCanceled = null;
}
}
6 changes: 6 additions & 0 deletions Source/Euonia.Application/UseCase/EmptyUseCaseInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Nerosoft.Euonia.Application;

/// <summary>
/// Represents a none input use case.
/// </summary>
public record EmptyUseCaseInput : IUseCaseInput;
6 changes: 6 additions & 0 deletions Source/Euonia.Application/UseCase/EmptyUseCaseOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Nerosoft.Euonia.Application;

/// <summary>
/// Represents the use case should not return any output.
/// </summary>
public sealed record EmptyUseCaseOutput : IUseCaseOutput;
40 changes: 40 additions & 0 deletions Source/Euonia.Application/UseCase/IUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Nerosoft.Euonia.Application;

/// <summary>
/// Defines an interface for use case.
/// </summary>
/// <typeparam name="TInput"></typeparam>
/// <typeparam name="TOutput"></typeparam>
public interface IUseCase<in TInput, TOutput>
where TInput : IUseCaseInput
where TOutput : IUseCaseOutput
{
/// <summary>
/// Executes the use case.
/// </summary>
/// <param name="input"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TOutput> ExecuteAsync(TInput input, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the presenter of the use case.
/// </summary>
IUseCasePresenter<TOutput> Presenter { get; }
}

/// <summary>
/// Defines an interface for use case.
/// </summary>
/// <typeparam name="TInput"></typeparam>
public interface IUseCase<in TInput>
where TInput : IUseCaseInput
{
/// <summary>
/// Executes the use case.
/// </summary>
/// <param name="input"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task ExecuteAsync(TInput input, CancellationToken cancellationToken = default);
}
8 changes: 8 additions & 0 deletions Source/Euonia.Application/UseCase/IUseCaseInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nerosoft.Euonia.Application;

/// <summary>
/// Defines the input data structure of a use case.
/// </summary>
public interface IUseCaseInput
{
}
8 changes: 8 additions & 0 deletions Source/Euonia.Application/UseCase/IUseCaseOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nerosoft.Euonia.Application;

/// <summary>
/// Defines the structure of use case execute result.
/// </summary>
public interface IUseCaseOutput
{
}
13 changes: 13 additions & 0 deletions Source/Euonia.Application/UseCase/IUseCaseOutputFailure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Nerosoft.Euonia.Application;

/// <summary>
/// Represents the structure of use case output when it is failure.
/// </summary>
public interface IUseCaseOutputFailure
{
/// <summary>
///
/// </summary>
/// <param name="exception"></param>
void Error(Exception exception);
}
Loading

0 comments on commit 034f57a

Please sign in to comment.