I haven't seen many such posts elsewhere and thought about doing a small write-up on my latest work with .net core. I had a couple of approaches to .net core, all stopped due to different issues with missing libraries and certain volatility in development. I was one of many waiting for version 2.0 to arrive to take another dive into core.
Here's the list of little things to remember about and potential issues which one can stumble upon when porting an app to .net core. I won't be going into details of each, just some food for thought:
-
ConfigurationManager is gone - library that comes with .core brings IOptions<T> interface, which allows for mapping settings.json file to POCO classes. All places, which use ConfigurationManager will have to get rewritten with either a cusom configuration framework or IOptions<T>.
Advantages:
- IOptions can be easily injected into classes using the DI scaffolding available out of the box
- Given it uses POCOs with nicely mapped properties along with lists and dictionaries, all strongly typed
- It reloads the values on change in the settings file
Disadvantages:
- We are bound to the IOptions interface, which seems to be an unneeded dependency
- Application reads the underlaying POCO when IOptions value is accessed - which means any errors will be delayed until that time
- In case we don't need the reloading functionality IOptions doesn't seem that useful, for the extra boilerplate it brings to the table
UPDATE:
You can actually download the following nuget package to get ConfigurationManager back:
- DirectoryServices namespace has not been migrated - this library is required for LDAP connectivity. It is quite often used in enterpraise ecosystems and might be a blocker for many to be able to move to .net core.
Potential solutions:
- I've checked the only open source LDAP solution, which supports .net standard: https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard It's basic functionality works. Unfortunately it does not support SSL which is a must when you want to have a certficate based authentication.
- Write a separate proxy API for LDAP connectivity in C# or another language to be called from your .net core project - whichever is easier to route your LDAP calls.
Here's discussion on the work being done and migration of this feature to .net core in the future:
- Windows based functionalities are not available - I know this sounds like a no-brainer, but it took a bit before it dawned on me :). Anyone who is planning to port should take a serious look through the code base. Check if there are no windows registry usages hiding somewhere in the plumbing of the app.
- Rijndael encryption with 256-bit block size is not supported - in case your code uses RijndaelManaged to perform encryption with 256-bit block size, you'll have to find another implementation - such a BouncyCastle.
-
IHttpModule and IHttpHandler pipeline changed into .net core middleware - it has slightly changed how HTTP request processing pipeline works in .net core. There are no IHttpModule or IHttpHandler interfaces. The new guy in town is called .net core middleware. It's pretty easy to migrate modules to the new middleware. On top of it the DI scaffolding in .net core allows to inject dependencies to both constructor (singletons only given lifetime of middleware) and into the Invoke method - which is our request handling method. Read more below:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware?tabs=aspnetcore2x
-
Lazy Loading and edmx missing from EF Core - lazy loading hasn't been implemented yet in Entity Framework for .net core along with any feature based on .edmx.
Why lazy loading is not always the best idea can be read here in detail:
https://ardalis.com/avoid-lazy-loading-entities-in-asp-net-applications
It still is an important tool in any EF's user toolbelt, discussion on it and an open source alternative can be found here:
https://github.com/aspnet/EntityFrameworkCore/issues/3797
UPDATE:
In addition to missing lazy loading, at least for now certain functionalities are not available through DataAnnotations or convention and require explicit entry in code. Among others composite keys. Hence when finding some features missing check, whether some other EF configuration approach is available.