Skip to main content

One post tagged with "CQRS"

View All Tags

Job Interview Technical Test Preparation

· 2 min read
Mark Burton
Software Engineer & Technical Writer

docs.microsoft.com Apply to a controller action by specifying it in the signature public IActionResult EncodedName([ModelBinder(typeof(Base64StringBinder))] string name). Apply to a model using [ModelBinder(BinderType = typeof(AuthorEntityBinder))] and register in startup.cs

public void ConfigureServices(IServiceCollection services)  \\\{  services.AddMvc(options =>  \{  Insert at the top so this gets used before default binder  options.ModelBinderProviders.Insert(0, new AuthorEntityBinderProvider());  \\});  }
``` using a [model binder provider](https:/github.comaspnetDocstreemasteraspnetcoremvcadvancedcustom-model-bindingsampleCustomModelBindingSample) ``` csharp
public class AuthorEntityBinderProvider : IModelBinderProvider \\\{ if (context.Metadata.ModelType == typeof(Author)) \{ return new BinderTypeModelBinder(typeof(AuthorEntityBinder)); \\} return null; }
``` ## Decode base64 string
``` csharp string decodedJson = Encoding.UTF8.GetString(Convert.FromBase64String(value));

Deserialise

json convert

10 //  "Name": "Apple",
11 // "ExpiryDate": "2008-12-28T00:00:00",
12 // "Price": 3.99,
13 // "Sizes": [
14 // "Small",
15 // "Medium",
16 // "Large"
17 // ]
18 /\}
19
20 Product deserializedProduct = JsonConvert.DeserializeObject<Product />(output);

without netwonsoft csharp [DataContract] public class Product \\\{ [DataMember] public string Name \{ get; set; \\} [DataMember] public DateTime ExpiryDate \\{ get; set; \} } public static string WriteFromObject() \\{ Product user = new Product("Bob", DateTime.Now); MemoryStream ms = new MemoryStream(); Serializer the User object to the stream. DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Product)); ser.WriteObject(ms, product); byte[] json = ms.ToArray(); ms.Close(); return Encoding.UTF8.GetString(json, 0, json.Length); \} public static User ReadToObject(string json) \\{ Product deserializedProduct = new Product(); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)); DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedUser.GetType()); deserializedUser = ser.ReadObject(ms) as Product; \} ##As a action filter decorate the controller action with [DecodingFilter]

```  #CQRS
[Martin Fowler - Command Query Responsibility Segregation](https:/www.martinfowler.comblikiCQRS.html) #Message queues ##AMQP
[Azure Service Bus .NET Standard client library ](https:/www.nuget.orgpackagesMicrosoft.Azure.ServiceBus)
[Using Service Bus from .NET with AMQP 1.0](https:/docs.microsoft.comen-usazureservice-bus-messagingservice-bus-amqp-dotnet) Void - Action<string /> prints = x => \\{ Debug.WriteLine(x); \}; Returns - Func&lt;int, int, int&gt; add = (x, y) => \\{ return x + y; \};