Expérience du portage d'un projet d'entreprise hérité avec Net Framework vers Net Core
Partie introductive
, Enterprise- C .Net Framework .Net Core. , , Microsoft, , , . , .
: Enterprise , ( C# Net Framework):
- ASMX web-
- WCF
- Workflow Foundation
- Web- WebForms ASP.NET MVC 4
- SQL Server Reporting Services
- Windows Forms
Net Core:
- ( , )
- NetCore: , ,
, — , . , . , .
, (Framework Core), NetStandard ( — netstandard2.0).
, NetCore, :
- Windows Communication Foundation. API , API
- Workflow Foundation
- ASP.NET Web Forms ( System.Web)
- API MSMQ
API , , , . .
, ,
Portatibility Analyzer
Portatibility Analyzer target' (NetCore, NetFramework, NetStandard, Mono, ...) , , API . Visual Studio.
( #if
) , API .Net Framewrk .Net Core.
#if
:
- API namespace' .Net Core
- API
- .Net Core
, :
: Net Framework NetStandard NetCore:
#if NETFRAMEWORK
#elif NETSTANDARD || NETCOREAPP
#endif
NetCore NetFramework ( , API, .NetStandard2.0):
#if NETFRAMEWORK
#elif NETCOREAPP
#endif
, runtime' .
Target' *.csproj :
<TargetFrameworks>netstandard2.0;net471;netcoreapp3.1</TargetFrameworks>
API
API, NetStandard NetCore . , , WCF, , .
, WCF TransactionFlowAttribute
, , , , :
#if NETFRAMEWORK
#elif NETSTANDARD || NETCOREAPP
namespace System.ServiceModel
{
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class TransactionFlowAttribute : Attribute, System.ServiceModel.Description.IOperationBehavior
{
public TransactionFlowAttribute(TransactionFlowOption transactions)
{
Transactions = transactions;
}
public TransactionFlowOption Transactions { get; }
public void AddBindingParameters(OperationDescription operationDescription,
BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
}
public void ApplyDispatchBehavior(OperationDescription operationDescription,
DispatchOperation dispatchOperation)
{
}
public void Validate(OperationDescription operationDescription)
{
}
}
public enum TransactionFlowOption
{
NotAllowed,
Allowed,
Mandatory,
}
}
#endif
NuGet
NuGet , NetFramework and NetCore.
:
- ( )
- (Bootstrapper)
Net Framework app.config, web.config, XML API : System.Configuration
System.Configuration.ConfigurationManager. , AppSettings ConfigurationSection.
NetCore API, (JSON, INI, XML) (, , . .)
? : . , , .
- , NuGet System.Configuration.ConfigurationManager.
NetCore . , ( ConfigurationSection
)
EventLog
API System.Diagnostics
, ILogger
, messageLevel (Debug, Info, Warning, Error) . NLog c ILogger
.
NetCore API: Microsoft.Extensions.Logging, ILogger<T>
.
ILogger
, , Microsoft.Extensions.Logging.ILogger<T>
, , : NLog, log4Net, Serilog ..
NetCore Microsoft.Extensions.DependencyInjection
ServiceCollection
, :
- Singleton —
- Scoped — , Http-
- Transient —
: ASP.NET Core.
:
- , . - , - - ,
- IoC- ( , )
Global Assembly Cache
Global Assembly Cache, .
Net Core GAC, AssemblyResolver, .
, API , .
*.cproj
SDK: <Project Sdk="Microsoft.NET.Sdk">
<TargetFramework>netcoreapp3.1</TargetFramework>
Windows Forms
NetCore 3.0 Windows Forms, Net Core 3.1 legacy ,
.
, "":
- DataGrid . DataGridView;
- ToolBar. ToolStrip;
- MainMenu. MenuStrip;
- ContextMenu. ContextMenuStrip.
Microsoft Windows Forms .NET Core,
.
Windows Forms NetCore 3.0 Visual Studio 2019, GUI Net Framework, NetCore 3.0, .
ASP.NET MVC Asp Net Core MVC
Windows Form , - .
— Global.asax
Startup
.
— System.Web
HttpSession
, Cookies
, HttpRequest
. . .
— , , , , HTTP .
: HTTP ASP.NET Core . Middleware. :
Middleware:
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Use(async (context, next) =>
{
// Do work that doesn't write to the Response.
await next.Invoke();
// Do logging or other work that doesn't write to the Response.
});
app.Run(async context =>
{
await context.Response.WriteAsync("Hello");
});
}
}
API , Razor
, : ASP.NET Core MVC : ASP.NET Core MVC.
— Bundler' js css , : ASP.NET Core
ASPNET ASMX AspNetCore WebAPI
- SOAP
HTTP JSON XML.
asmx WebAPI WebMethod
Action POST asmx . , SOAP
. , Rest-.
— , SOAP
, : SoapCore.
— JSON-RPC, NetCore, AspNet Core Middleware.
Microsoft guide AspNetCore Middleware SOAP : Custom ASP.NET Core Middleware Example.
ASPNET WebApi AspNetCore WebAPI
, : .
guide': -API ASP.NET ASP.NET Core
MVC:
Global.asax
Startup
- Logger, Exception Handler
- ..
ASPNET Web Forms Blazor
, , , .
Web Forms Blazor:
- ()
- Code-behind :
- Java-Script ( C#)
2 :
- aspx , XML ( C#) ( , grid . .), html- aspx
- : Blazor- code-behind
, , ASPNET Web Forms .
WCF
NetCore WCF Client API:
- BasicHttpBinding, NetTcpBinding
- security Message , Transport
WCF Net Core, :
WCF AspNetCore WebAPI asmx : — action- WCF. : Post-, URL https://you-service.com/MethodName
, JSON-RPC.
— AspNetCore gRPC: WCF " — " gRPC RPC
WCF :
[ServiceContract]
public interface IItemService
{
[OperationContract]
Task<Item> GetItem(int id);
}
[DataContract]
public class Item
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
}
gRPC protobuf :
message GetItemRequest {
int32 id = 1;
}
message Item {
int32 id = 1;
string name = 2;
}
service ItemService {
rpc GetItem(GetItemRequest) returns (Item);
}
— , :
- WebAPI REST, JSON-RPC
- gRPC
Workflow Foundation
Workflow Foundation ( Microsoft, , ), :
- CoreWF
- ASP.NET Core Worker' : ASP.NET Core
- , Workflow Core
Workflow Foundation, . ?
? , , , ,
. : HTTP Rest like ,
( ) — gRPC . … ( ) Web Forms.
UPD: Portatibility Analyzer.