
In fast paced technology world, developers discover new insights practically on a daily level. Surely you have experienced these moments of almost divine wisdom, ending with “Now I know xyz can do that” or “I have to be aware of xyz” or “Eureka!”. I have recorded my moments of clarity, or Ahaaas as I call them, hoping that some of them will prove useful to you, whether you’d be dealing with .NET development, Azure or Docker.
.NET
- Mocking authentication in ASP.NET Core 3.0 integration tests https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests#mock-authentication
- Even though ASP.NET Core
IConfiguration
entry names are case-insensitive,ConfigurationBinder.Bind()
method is not and property name casing does matter. Prefer using Configure() options extension method to bind configuration sections to option types. - Be careful when using array values in
IConfiguration
data sources, especially if you consider overriding with environment specific configurations https://rimdev.io/avoiding-aspnet-core-configuration-pitfalls-with-array-values/ - If you cannot rely on your reverse proxy, it is possible to add client and IP rate limiting to ASP.NET Core. Source code and installation instructions are available at https://github.com/stefanprodan/AspNetCoreRateLimit. Remember, however, that Kestrel should not be used as a public facing web server.
- Controller input model validation can be automated using
[ApiController]
attribute and annotations fromDataAnnotations
namespace https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation - When using
[DataMember]
attribute to annotate serialization model properties, do not forget to add[DataContract]
to enclosing type as well. Most of traditional JSON serializers, such as Newtonsoft and Jil, honor property attributes, but expect type to be annotated as well.System.Text.Json.JsonSerializer
surprisingly does not utilize attributes fromSystem.Runtime.Serialization
namespace and uses its own annotations - Cool portability tool from .NET to .NET core comes from, you wouldn’t believe it, AWS team. More details https://aws.amazon.com/blogs/aws/announcing-the-porting-assistant-for-net/
System.Net.Mail.SmtpClient
is obsolete for some time; recommended alternative is MailKitIApplicationLifetime
service is obsolete from .Net Core 3.0. If you utilize generic host, useIHostApplicationLifetime
instead https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.iapplicationlifetime- Imagine you have a concrete type implementing two different interfaces. Now imagine you register this type for each interface as a singleton in DI container. When resolving each interface, you will end up with a different instances, i.e. .NET core DI container will create two instances instead of sharing single one.
- If you are looking for Blazor components that you can use for commercial projects, Syncfusion offers a handful via their community license https://www.syncfusion.com/products/communitylicense
Azure
- If you use sessions with Azure Service Bus, be sure to assign session identifier to messages before sending them. Service Bus will not complain if session is missing on enqueue, but will make hell for consumers on delivery and practically keep messages in queue and attempt to deliver them, until expired.
- You can use Azure Log Analytics to collect custom virtual machine logs https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-sources-custom-logs. In Portal, open your Log Analytics workspace and go to Advanced Settings->Data->Custom Logs. You can also collect Windows Event and IIS Logs, as well as Linux Syslog, in a similar fashion.
- Data sampling, configured in Application Insight’s Usage and Estimated Costs, has no effect if you are using ASP.NET core applications without modifying telemetry sampling configuration. Ingested data can significantly increase costs, especially if Azure Functions are used, so use Daily Cap setting to get notified if the amount ingested passes the limit.
- Microsoft Q&A is generally available and should help you find any technical information regarding Azure services https://docs.microsoft.com/en-us/answers/products/
Miscellaneous
- Nice overview of most commonly used open source licenses, with usage restrictions https://choosealicense.com
- Steve Dunn used Blazor to recreate original Pacman http://pacmanblazor.azurewebsites.net. With a little bit of JS interop, he was able to demonstrate potential of client-side Blazor running on WebAssembly. Source code can be found on Github
- Postman automatically converts POST requests if it receives a 301 redirect status code. In this situation, it drops any request content and issues a GET request to redirecting location without any body data. This can lead to trouble, as user is never notified of such change during request execution. To avoid such issues, better turn off automatic redirects in Postman settings.
- Elasticsearch .NET client version 7.1.0 seems to have issues when running on .NET core 3.0. Updating client to latest version (7.8.0 at the moment of writing) seems to help.
Comments