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
public class LoginController : AppController<ILoginService> | |
{ | |
public LoginController(ILoginService service, IWebHostEnvironment environment) : base(service, environment) { } | |
[AllowAnonymous] | |
[HttpPost("AuthenticateAsync")] | |
public async Task<IActionResult> AuthenticateAsync([FromBody] LoginModel model) => | |
( | |
await Service | |
.AuthenticateAsync(model.UserName, model.Password) |
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
public static class ServiceResultExtensions | |
{ | |
// Probably one of the exceptions we designed, so we test the exception first. | |
public static ServiceResult<T> GetResult<T>(this T result) => result is IResultPatternProxy proxy | |
? CreateServiceResult<T>(proxy.Kind, result, proxy.WarningDescription, proxy.ExceptionDescriptions) | |
: ServiceResult<T>.Success(result); | |
private static ServiceResult<T> CreateServiceResult<T>(ResultKinds kind, object result, string warning, ExceptionDescriptions exceptionDescriptions) => | |
Activator.CreateInstance(typeof(ServiceResult<>).MakeGenericType(typeof(T)), kind, result, warning, exceptionDescriptions) as ServiceResult<T>; | |
} |
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
public class Startup | |
{ | |
public Startup(IConfiguration configuration) => Configuration = configuration; | |
public IConfiguration Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddAutoMapper |
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
public static class ServiceCollectionExtensions | |
{ | |
public static IServiceCollection AddResultPattern(this IServiceCollection services) | |
{ | |
services.AddSingleton<IObjectBuilder, SimpleDynamicObjectBuilder>(); | |
//services.AddSingleton(typeof(IResultPatternAspect<>), typeof(ResultPatternAspect<>)); | |
services.AddSingleton<IResultPatternAspecFactory, ResultPatternAspecFactory>(); | |
return services; | |
} |
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
private static void Main() | |
{ | |
var dynamicObjectBuilder = new DynamicObjectBuilder("Domain_Assembly"); | |
Console.WriteLine("***** Object With Base Class & Interface *****"); | |
ObjectWithBaseClassAndInterfaceAndCustomProperty(dynamicObjectBuilder); | |
Console.ReadLine(); | |
ObjectWithInterface(dynamicObjectBuilder); | |
Console.ReadLine(); |
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
public class User | |
{ | |
public string Name { get; set; } | |
} | |
public interface IInterface | |
{ | |
public string Property1 { get; set; } | |
} |
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
public class BuilderPropertyInfo | |
{ | |
public string Name { get; set; } | |
public Type Type { get; set; } | |
public bool IsInterfaceImplementation { get; set; } | |
} | |
public interface IObjectBuilder | |
{ | |
object CreateObject(string name, BuilderPropertyInfo[] properties = null, Type baseClass = null, Type[] interfaces = null, bool autoGenerateInterfaceproperties = false); |
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
public interface IResultPatternAspecFactory | |
{ | |
TService Create<TService>(TService service); | |
} | |
public class ResultPatternAspecFactory : IResultPatternAspecFactory | |
{ | |
public ResultPatternAspecFactory(IServiceProvider serviceProvider) => ServiceProvider = serviceProvider; | |
public IServiceProvider ServiceProvider { get; } |
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
public interface ILoginService : IService | |
{ | |
Task<LoginDto> AuthenticateAsync(string userName, string pw); | |
LoginDto Authenticate(string userName, string pw); | |
} | |
public class LoginService : Service, ILoginService | |
{ | |
public LoginService(IMapper mapper) : base(mapper) { } |
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
public static class ServicesResultExtensions | |
{ | |
public static IActionResult ToActionResult<T>(this ServiceResult<T> result, AppController controller, [CallerMemberName] string callerName = "") => | |
// C# 8.0 | |
// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/switch-expression | |
// In the Front-End program, we test the value of the Kind property | |
// For the object we received via Response, | |
// and on the basis of it we build the result for the user. | |
result?.Kind switch | |
{ |
NewerOlder