@RoutingKey(‘abc’) class Foo { public name: string | undefined; public age: number | undefined; public gender: string | undefined; constructor(init?: Partial<Foo>) { if (init) { Object.assign(this, init); } } } const foo = new Foo({ name: ‘something’ }); https://stackoverflow.com/a/72028371/1515209 Read more →
Category: C#
.net core catch all exception handler
app.UseExceptionHandler(options => { options.Run( async context => { var error = context.Features.Get<IExceptionHandlerFeature>(); if (error is object) { Log.Error( “EXCEPTION {method} {url} {query} => {exception}”, context.Request.Method, context.Request.Path.Value, context.Request.QueryString.Value, error.Error); } }); }); Read more →
OAuth2 scopes vs Roles
Scopes are typically used when an external application wants to gain access to the user’s data via an exposed API. They determine what the client application can do. Role (or group) based access is typically used within an application to determine what a user can do. https://stackoverflow.com/a/60943090/1515209 See also: https://www.linkedin.com/pulse/oauth-roles-scopes-pablo-cibraro/?articleId=6675773770986336256 Read more →
What does Dependency Injection mean by saying it can inject at runtime?
The service type is defined at compile time. This is normally in the form of an interface or a (sometimes abstract) base class. The key point here is Liskovs substitution principle It states that, in a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e., objects… Read more →
Exception capture in .NET Core
app.UseExceptionHandler(options => { options.Run( async context => { var error = context.Features.Get<IExceptionHandlerFeature>(); if (error is object) { Log.Error( “EXCEPTION {method} {url} {query} => {exception}”, context.Request.Method, context.Request.Path.Value, context.Request.QueryString.Value, error.Error); } }); }); Read more →
Debug XmlSerializer
var serializer = new XmlSerializer(typeof(<x>)); serializer.UnknownAttribute += (sender, args) => System.Diagnostics.Debug.Fail($”Unknown attribute { args.Attr.Name }=\'{ args.Attr.Value }\'”); serializer.UnknownNode += (sender, args) => System.Diagnostics.Debug.Fail($”Unknown Node: {args.Name}\t{args.Text}”); serializer.UnknownElement += (sender, args) => System.Diagnostics.Debug.Fail($”Unknown Element: { args.Element.Name }\t{ args.Element.InnerXml}”); serializer.UnreferencedObject += (sender, args) => System.Diagnostics.Debug.Fail($”Unreferenced Object: { args.UnreferencedId }\t{ args.UnreferencedObject.ToString() }”); Read more →
Access app.config from a texttemplate
<#@ template debug=”false” hostspecific=”true” language=”C#” #> <#@ assembly name=”System.Core” #> <#@ assembly name=”System.Configuration” #> <#@ import namespace=”System.Linq” #> <#@ import namespace=”System.Text” #> <#@ import namespace=”System.Collections.Generic” #> <#@ import namespace=”System.Configuration” #> <#@ output extension=”.tt.cs” #> <# var projectPath = Host.ResolveAssemblyReference(“$(ProjectDir)”); var configFile = projectPath + “App.config”; var map = new ExeConfigurationFileMap() { ExeConfigFilename = configFile }; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);… Read more →
CQS & CQRS
CQS means “Command-query separation”. It was introduced by Bertrand Meyer as part of his work on the Eiffel programming language. A method is either a command performing an action, or a query that returns data, but not both. Being purely action-performing methods, commands always have a void return type. Queries, on the other hand, should not have any observable side… Read more →
Software Development Principles & Patterns
Who even gives a ****? I do. My Software Development Principles Unit Testing / Test Driven Development / Behaviour Driven Development CQRS Command and Query Responsibility Separation SOLID Single Responsibility Principle Open/Closed Principle Liskov’s Substitution Principle Interface Segregation Principle Dependency Inversion Principle AOP Aspect-Oriented Programming Unit Testing A unit as the smallest testable part of an application. In object-oriented programming, a… Read more →
Updated Command & Query Handlers
I’ve recently updated my definitions for Query Handlers. I’ve changed the original IQuery<Tresult> to IReturn<TResult> as, for me, it better reflects the intention of the [marker] interface. public interface ICommandHandler<TCommand> { void Execute(TCommand command); } public interface IReturn<TResult> { } public interface IQueryHandler<TQuery, TResult> where TQuery : IReturn<TResult> { TResult Execute(TQuery query); } Read more →