();
Console.WriteLine( $"{dx2.GetPong()}" );
ReleaseContainer();
}
private static void ReleaseContainer()
{
// dispose container and services in it
if(ioc is IDisposable)
{
Console.WriteLine("Can dispose stuff !");
( (IDisposable)ioc).Dispose();
}
}
}
}
}}}
=== Example output ===
{{{
Hello World DI!
TestOne
Constructed dummy 37a7cced-15c3-4b33-9eec-55f0fb58ce8c !
Pong 37a7cced-15c3-4b33-9eec-55f0fb58ce8c !
Pong 37a7cced-15c3-4b33-9eec-55f0fb58ce8c !
Constructed snafu 619160b5-6e67-4396-8555-f453bd1ad06f !
Snafu 619160b5-6e67-4396-8555-f453bd1ad06f related with Pong 37a7cced-15c3-4b33-9eec-55f0fb58ce8c !!
Snafu 619160b5-6e67-4396-8555-f453bd1ad06f related with Pong 37a7cced-15c3-4b33-9eec-55f0fb58ce8c !!
Constructed transx 6cf6600a-e622-46fd-8d10-3b6015601911 !
Transx 6cf6600a-e622-46fd-8d10-3b6015601911 !
Constructed transx c666091c-efe9-407f-8659-6c1bdc7e2b7f !
Transx c666091c-efe9-407f-8659-6c1bdc7e2b7f !
Constructed transx 421a63ca-0e93-4656-ba5c-c8909774827c !
Transx 421a63ca-0e93-4656-ba5c-c8909774827c !
Can dispose stuff !
Disposing transx 421a63ca-0e93-4656-ba5c-c8909774827c !
Disposing transx c666091c-efe9-407f-8659-6c1bdc7e2b7f !
Disposing transx 6cf6600a-e622-46fd-8d10-3b6015601911 !
Disposing snafu 619160b5-6e67-4396-8555-f453bd1ad06f !
Disposing dummy 37a7cced-15c3-4b33-9eec-55f0fb58ce8c !
TestTwo
Constructed dummy 7233afd9-9f2e-43a4-ae1a-bc0abba6abc7 !
Constructed snafu 10298883-4f16-4383-b5b7-ce9e5ad90715 !
Snafu 10298883-4f16-4383-b5b7-ce9e5ad90715 related with Pong 7233afd9-9f2e-43a4-ae1a-bc0abba6abc7 !!
Pong 7233afd9-9f2e-43a4-ae1a-bc0abba6abc7 !
Pong 7233afd9-9f2e-43a4-ae1a-bc0abba6abc7 !
Can dispose stuff !
Disposing snafu 10298883-4f16-4383-b5b7-ce9e5ad90715 !
Disposing dummy 7233afd9-9f2e-43a4-ae1a-bc0abba6abc7 !
}}}
== Eager service bean instantiation ==
To instantiate a service/bean before being used else where add it as an argument in the Configure method that belongs to the Startup class.
== RBAC role based authorization ==
* https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.0&tabs=visual-studio%2Caspnetcore2x
* https://docs.microsoft.com/en-us/aspnet/core/security/authorization/secure-data?view=aspnetcore-2.0
* https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-2.0
* https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-2.0
Identity is enabled for the application by calling UseAuthentication in the Configure method. Startup.cs in dotnet core to init the services/beans.
In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup.
* About.cshtml
{{{
@{
ViewData["Title"] = "About";
}
@ViewData["Title"].
@ViewData["Message"]
Use this area to provide additional information.
}}}
* HomeController.cs
{{{#!highlight csharp
// method About related with About.cshtml
// ViewData["Message"] defined in the method and accessed inside the view in the About.cshtml
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
// return explicit view Orders
// return View("Orders");
// return both a view and a model
// return View("Orders", Orders);
}
}}}
View discovery searches for a matching view file in this order:
* Views/[ControllerName]/[ViewName].cshtml
* Views/Shared/[ViewName].cshtml
Pass data to views using several approaches:
* Strongly-typed data: viewmodel
* Weakly-typed data
* ViewData (ViewDataAttribute)
* ViewBag
Strong type sample
{{{
// CSHTML
@model WebApplication1.ViewModels.Address
Contact
@Model.Street
@Model.City, @Model.State @Model.PostalCode
P: 425.555.0100
To provide the model to the view, the controller passes it as a parameter:
// C#
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
var viewModel = new Address()
{
Name = "Microsoft",
Street = "One Microsoft Way",
City = "Redmond",
State = "WA",
PostalCode = "98052-6399"
};
return View(viewModel);
}
}}}
Angular automatically passes an antiforgery token in a request header named X-XSRF-TOKEN. The ASP.NET Core MVC app is configured to refer to this header in its configuration in Startup.cs:
{{{
public void ConfigureServices(IServiceCollection services)
{
// Angular's default header name for sending the XSRF token.
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
services.AddMvc();
}
}}}
== Install dotnetcore in CentOS ==
* rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
* yum install dotnet-sdk-2.2
* dotnet new console --name hello-console
* yum install epel-release
* yum install nodejs
* dotnet new reactredux --name "react-test"
* cd react-test/
* dotnet clean
* dotnet build
* dotnet publish
* dotnet bin/Debug/netcoreapp2.2/publish/react-test.dll
* vi Program.cs
{{{#!highlight csharp
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace react_test
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup().UseUrls("http://0.0.0.0:5000;https://0.0.0.0:5001");
}
}
}}}
== Kestrel ==
* https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1
Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included by default in ASP.NET Core project templates.
Kestrel supports the following scenarios:
* HTTPS
* Opaque upgrade used to enable WebSockets
* Unix sockets for high performance behind Nginx
* HTTP/2 (except on macOS†)
== Install dotnetcore in Debian buster ==
{{{
wget https://packages.microsoft.com/config/ubuntu/19.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-3.1 nodejs npm dotnet-sdk-2.1
}}}
* https://code.visualstudio.com/
* cd ~/Downloads
* wget https://go.microsoft.com/fwlink/?LinkID=760868
* mv index.html\?LinkID\=760868 vscode.deb
* sudo dpkg -i vscode.deb # 1.43.2
* code &
* Install extension ms-dotnettools.csharp
* Install extension Eclipse Keymap alphabotsec.vscode-eclipse-keybindings
=== Angular project ===
{{{#!highlight bash
# nodejs --version # v12.16.2
# npm --version # 6.14.4
# dotnet --version # 3.1.201
cd ~
dotnet new angular --name test # creates folder test with the project
cd test
dotnet clean
dotnet build
dotnet run
https://localhost:5001/
# There are issues building the project on the sandbox folder shared with windows through a mounted folder.
}}}
== ILspy ==
* https://github.com/icsharpcode/ILSpy open-source .NET assembly browser and decompiler.
== Install MSSQL server 2017 express in Debian Linux buster ==
* https://dev.to/nabbisen/microsoft-sql-server-2017-on-debian-n77
{{{#!highlight bash
sudo apt-get install apt-transport-https
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
sudo apt update
# deb http://ftp.debian.org/debian jessie main
echo "deb http://ftp.debian.org/debian jessie main" >> /etc/apt/sources.list
sudo apt update
sudo apt-get install libssl1.0
sudo apt-get install mssql-server
sudo systemctl restart mssql-server.service
sudo /opt/mssql/bin/mssql-conf setup
# "Express" edition is free to use with limitations.
# Choose 3) Express (free)
# Enter the SQL Server system administrator password: **********
# The licensing PID was successfully processed. The new edition is [Express Edition].
# install sqlcmd
sudo apt install mssql-tools
nano ~/.bashrc
PATH=$PATH:/opt/mssql-tools/bin/
. ~/.bashrc # reload .bashrc
# tcp6 0 0 :::1433 :::* LISTEN
sqlcmd -S localhost -U sa -P ********
# 1> exec sp_databases
# 2> go
# https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15
# select name from sys.databases
# go
# exit
# example connection string
# Data Source=LOCALHOST;Initial Catalog=TestDB;User Id=sa;Password=********;App=TestApp
}}}
== Swagger ==
* https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=netcore-cli
* dotnet add test.csproj package Swashbuckle.AspNetCore
{{{#!highlight csharp
using Microsoft.OpenApi.Models;
/* in Startup.cs ConfigureServices */
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); });
/* in Startup,cs Configure */
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });
}}}