Injecting ClaimsPrincipal into Service / Business logic – layers (.NET Core)

So… You want to add authorization or atleast being able to figure out the username in the business logic layer.
What i’ve previously done is inject the username from the ui layer into the service-layer through input params on all methods (bad).
To inject the claimsprincipal in .NET Core we utilize the builtin IOC capabilities and simply
services.AddTransient(s => s.GetService().HttpContext.User); in Startup.cs
with the above we can simply just state (in the constructor) that our service / class / what ever needs a ClaimsPrincipal

Note: This requires the user is authenticated AND that you are using Claims (obviously).

Building on this, we could do something like the following;
Create a new service interface something like ICurrentUserProvider, with a method like public YourUserModel GetCurrentUser().

Implement the provider, injecting ClaimsPrincipal, your DbContext and maybe a caching service.

The convert the ClaimsPrincipal to your YourUserModel save it to the cache and return it.

Outlook/Gmail removes line breaks

I had a run in, with the particular feature of outlook, developing an application that sent plain-text emails.
I had code very similar to the following

which would result in the following plain-text
Hello,\r\n
Please update the following:\r\n
\r\n
Item1\r\n
Item2\r\n
Item3\r\n

But outlook would show me the following
Hello,\r\n
Please update the following:\r\n
Item1Item2Item3

Most solutions to this include creating the email as HTML instead.
This is fortunately NOT needed.
Outlook uses certain rules to determine something called “Continuation”.
* Every message starts with continuation off.
* Lines less than 40 characters long do not trigger continuation, but if continuation is on, they will have their line breaks removed.
* Lines 40 characters or longer turn continuation on. It remains on until an event occurs to turn it off.
* Lines that end with a period, question mark, exclamation point or colon turn continuation off. (Outlook assumes it’s the end of a sentence?)
* Lines that turn continuation off will start with a line break, but will turn continuation back on if they are longer than 40 characters.
* Lines that start or end with a tab turn continuation off.
* Lines that start with 2 or more spaces turn continuation off.
* Lines that end with 3 or more spaces turn continuation off.

Credits:

mtruesdell and his SO answer here