Save yourself some time in your ASP.NET Core projects with these helpful utilities.
Here at Endpoint Systems we're cranking out a number of high-quality ASP.NET Core web apps for the masses. As a result, we're finding ourselves building a number of small but (we think!) helpful utilities for making the journey a little easier for all of us. We'll keep this blog post fresh with additional packages as they show up down the road, so here's a list of our latest packages.
UrlFriendly
Sometimes putting together a SEO or index-friendly slug/URL can be a challenge, especially when dealing with European characters with emaulets and the like. Johan Boström, whose surname highlights part of the problem we're facing, posted a great snippet of code wherein he builds some code to fix this. We've simply taken this code snippet (he's got a GitHub for it, but it's just demo code) and made a library and NuGet package out of it.
NuGet package can be found here.
YamlMarkdown
YAML is a fascinating "schema-less" language with weird constructs that make it good for terse outlining (tables of contents, for example) and other human-readable output, so naturally it's used for stuffing system commands into for painful troubleshooting issues in Docker and 43,000 other tales of woe on StackOverflow. Still, it has its good moments, like adding context to a Markdown file in a format often referred to as "YAML front matter in a Markdown" or something similar.
While apps like Wyam have this in their infrastructure as a feature, nobody really seemed to have it as something that could be quickly/easily consumed as part of a web app, and that's how the YamlMarkdown package was formed. This NuGet package combines YamlDotNet and the Markdig Markdown parsing engine and makes a dead-simple class for parsing a file or TextReader object and deserializing your YAML object type as well as giving you your content in the original Markdown and generic HTML renderings.
This comes in handy because Markdig supports YAML frontmatter parsing by ignoring it, at least for now.
NuGet package can be found here.
SiteMapIndex
This package is designed to assist those building ASP.NET Core websites with a sizeable amount of URLs that need to go into a sitemap. If you look at the sample code, we build out a number of unique SiteMap objects, tie them together with the SiteMapIndex, and then use Carter to map the files to the router so the application knows to map them.
NuGet package can be found here.
Unique
What initially started as a way to replace System.Web.Security.Membership.GeneratePassword
from legacy ASP.NET has turned into a unique ID generator that's shorter than using GUIDs. You can use it to build identifiers similar to YouTube or Firestore IDs, if needed. We ran a test building identifiers with 7 alphanumeric characters (and no punctuation characters) and managed to get 10 million unique identifiers out of it. We didn't try a larger number, but, assuming our math isn't wrong, it seems you should be able to get at least 62^7
or 3.522 trillion unique identifiers out of it.
Sample output:
[Fact]
public void TestUnique()
{
var hs = new HashSet<string>();
for (int i = 0; i < 100; i++)
{
var u = Unique.Unique.Generate(8, 0);
hs.Add(u);
output.WriteLine(u);
}
}
Xq8Lnhkq
udPe7BhM
mvsKFYjy
IiQrpozS
hcbskLr4
VmsINq1M
O2rMu84n
f6sHbtk1
XbDcLacW
idhJKidB
xAgditbO
TuQCrY3U
...
NuGet package can be found here.
DynamicTableEntityJsonSerializer
This one is a bit of a mouthful, but essentially what it does is take the original NuGet package as authored by DoguArslan and add the ability to serialize directly to an ExpandoObject by taking out the EdmType bits. It might make more sense to look at the source code here.
Essentially, for each property in the DynamicTableEntity, a new JSON object was created which included the EdmType. We simplified the property so it would be more ExpandoObject-compatible by doing away with the EdmType. That's it - literally the only difference (well, that and we updated the code to use .NET Core 3.1, and we're in a public repo).
NuGet package can be found here.
Looking for help building or integrating your web application with cloud and enterprise resources? Contact us for a quote - not only is it free, but we can help you find what you're looking for at a better price than most consulting firms!