NetPackageAnalyzer–part 10–commits per year and folder
The .NET Tool , https://www.nuget.org/packages/netpackageanalyzerconsole , can now analyze a solution and see the commits per year and folder
The .NET Tool , https://www.nuget.org/packages/netpackageanalyzerconsole , can now analyze a solution and see the commits per year and folder
The .NET Tool , https://www.nuget.org/packages/netpackageanalyzerconsole , can now analyze a solution and see the different correlations of a project in a radar form
This is what have been generated to itself
Install from https://nuget.org/packages/netpackageanalyzerconsole
Assemblies with number of public classes Assemblies with Public methods Classes with Public methods
See https://ignatandrei.github.io/PackageAnalyzer/docs/Analysis/NetPackageAnalyzer/summaryPublicClasses
I wanted to have a tool that can analyze a C# solution with all the dependencies ( project relations, packages, commits)
It generates a graph of the dependencies for
Along with the graph, it also generates
If you want to see how it looks like, you can see how he analyses himself at Analyzer
ID | Name |
---|---|
1 | Part 1 |
2 | Part 2 |
3 | Part 3 |
I did not have the opportunity to migrate from a database from another . But seems to me that , when using EF, the principal problem will be the stored procedures, not the code that EF ( and providers) are generating automatically. Yes, there are some problems ( see part 1 and part 2) , but those seems not so important and easy to solve.
ID | Name |
---|---|
1 | Part 1 |
2 | Part 2 |
3 | Part 3 |
I wanted to see if there are any differences in EFCore database providers listed at
https://learn.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli
I want to test the capabilities for each one within a standard choice of tables , in order to know the capabilities
I choose only those that have a version for current STS / LTS , whatever it is current.
( I am particularly interested in SqlServer vs Sqlite )
For MySql – there are 2 providers , Pomelo.EntityFrameworkCore.MySql and MySql.EntityFrameworkCore . Both have the same namespace and class for .UseMySql ( and other stuff)
So how to do it ? Fortunately, nuget supports alias .
So the code in csproj is
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" Aliases="PomeloEFMySql" /> <PackageReference Include="MySqlConnector" Version="2.2.5" Aliases="MySqlConnect" /> <PackageReference Include="MySql.EntityFrameworkCore" Version="7.0.5" Aliases="MySqlEFOracle" /> <PackageReference Include="MySql.Data" Version="8.1.0" Aliases="OracleMySql"/>
And the code in global.cs
extern alias OracleMySql; extern alias PomeloEFMySql; extern alias MySqlConnect; global using MySqlCNBOracle = MySqlEFOracle.Microsoft.EntityFrameworkCore.MySQLDbContextOptionsExtensions; global using MySqlOracle = OracleMySql.MySql.Data.MySqlClient; global using MySqlEF = MySqlEFOracle::Microsoft.EntityFrameworkCore; global using PomeloCN= MySqlConnect::MySqlConnector; global using PomeloEF = PomeloEFMySql::Microsoft.EntityFrameworkCore; global using PomeloMySqlCNB =PomeloEFMySql::Microsoft.EntityFrameworkCore.MySqlDbContextOptionsBuilderExtensions;
And the code to use it
case EFCoreProvider.Pomelo_EntityFrameworkCore_MySql: var serverVersion = PomeloEF.ServerVersion.AutoDetect(con); StepExecution.Current.Comment("version " + serverVersion.ToString()); PomeloMySqlCNB.UseMySql(builder,con, serverVersion) .EnableSensitiveDataLogging() .EnableDetailedErrors(); break; case EFCoreProvider.MySql_EntityFrameworkCore: MySqlCNBOracle.UseMySQL(builder,con); break;
You can find the results at https://github.com/ignatandrei/TestEFCoreDatabaseProviders and https://ignatandrei.github.io/TestEFCoreDatabaseProviders/
When a container is started for a test it works on a port ( 1433 for SqlServer). When a new test arrives ( with new tables ) , it cannot be on the same port . So the docker containers must be disposed when the test finishes. Also , the tests must be done in serial, not in paralel.
For parallelism, it is simple ( LightBDD + XUnit)
[assembly: CollectionBehavior(DisableTestParallelization = true)] [assembly: ClassCollectionBehavior(AllowTestParallelization = false)]
For disposing, can use IScenarioTearDown (LightBDD) or IAsyncLifetime (XUnit)
In my NuGet NetCoreUsefullEndpoints package I have had already registered the actual date as
var rh = route.MapGet(“api/usefull/dateUTC”, (HttpContext httpContext) =>
{
return Results.Ok(DateTime.UtcNow);
});
Now I want to register also the start date – the date where the application has been started.
1. How to do this ?
2. What will be the route ?
For 1 can be a static constructor or, better , the singleton in C# :
private static DateTime startDateUTC = DateTime.UtcNow;
For 2 it is more complicated
My solution ( just break compatibility, since I have not a v1 and v2) was the following
var rh = route.MapGet(“api/usefull/date/startUTC”, (HttpContext httpContext) =>
{
return Results.Ok(startDateUTC);
});var rhUTC = route.MapGet(“api/usefull/date/nowUTC/”,
(HttpContext httpContext) =>
{
return TypedResults.Ok(DateTime.UtcNow);
});rhUTC.AddDefault(corsPolicy, authorization);
So now I have same routing api/usefull/date
In order to do the shutdown, I have added the following extension
public static CancellationTokenSource cts=new ();
public static void MapShutdown(this IEndpointRouteBuilder route, string? corsPolicy = null, string[]? authorization = null)
{
ArgumentNullException.ThrowIfNull(route);
var rh = route.MapPost(“api/usefull/shutdown/”,
(HttpContext httpContext) =>
{
var h= cts.Token.GetHashCode();
cts?.Cancel();
return h;
});rh.AddDefault(corsPolicy, authorization);
}
This code defines a static field called “cts” in the “UsefullExtensions” class. “cts” is an instance of the “CancellationTokenSource” class, which is used to create a CancellationToken that can be used to stop the application gracefully.
The “MapShutdown” method is an extension method for IEndpointRouteBuilder that creates a new endpoint for a POST request to the “api/usefull/shutdown/” URL. When the request is received, the method cancels the “cts” CancellationTokenSource if it is not null, and returns the hash code of the CancellationToken. The method also sets the “corsPolicy” and “authorization” parameters for the endpoint.
You can call with
app.MapUsefullAll();
or with
app.MapShutdown
Anyway , the runAsync should be modified with
await app.RunAsync(UsefullExtensions.UsefullExtensions.cts.Token);
The “RunAsync” method of the “app” object is used to start the application and listen for incoming requests. The method takes a CancellationToken as an argument, which allows the application to be stopped gracefully by cancelling the token. In this case, the token is provided by the “cts” field of the “UsefullExtensions” class. The code uses the “await” keyword to wait for the task returned by “RunAsync” to complete before continuing.
I have received a suggestion : what if we just put into constructor what we need , and everything else ( such as ILogger ) are into fields ?
The Roslyn Source Code Generator will generate a constructor that calls the this constructor and will assign fields needed.
Let’s give an example : We wrote
public partial class TestDIFunctionAdvWithConstructor2Args
{
[RSCG_FunctionsWithDI_Base.FromServices]
private TestDI1 NewTestDI1;public TestDI2 NewTestDI2 { get; set; }
public readonly TestDI3 myTestDI3;
private TestDIFunctionAdvWithConstructor2Args(TestDI3 test, TestDI2 a)
{
myTestDI3 = test;
NewTestDI2 = a;
}}
and the generator will generate a new constructor with the required field
public partial class TestDIFunctionAdvWithConstructor2Args
{
public TestDIFunctionAdvWithConstructor2Args
(TestDI3 test, TestDI2 a, TestDI1 _NewTestDI1) : this (test,a)
{
this.NewTestDI1 = _NewTestDI1;
}//end constructor}//class
The code is non trivial – to find if a constructor exists, take his fields, generate new constructor with all fields.
But , as anything in IT , it is doable .
Now it is time to solve some issues There were 12 issues written by me – you can see here:
https://github.com/ignatandrei/RecordVisitors/issues?q=is%3Aissue+is%3Aclosed
Between the most important:
There seems little – but it takes a while.
The links for the project are now