Experience in porting a legacy enterprise project with Net Framework to Net Core

Experience in porting a legacy enterprise project with Net Framework to Net Core



net framework to net core



Introductory part



, 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: , ,


.NET Core .NET Framework , .



, โ€” , . , . , .



, (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.



Portatibility Analyzer





( #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.



https://docs.microsoft.com/ru-ru/dotnet/standard/library-guidance/media/cross-platform-targeting/nuget-package-multiple-assemblies.png





:



  • ( )
  • (Bootstrapper)




Net Framework app.config, web.config, XML API : System.Configuration System.Configuration.ConfigurationManager. , AppSettings ConfigurationSection.



NetCore API, (JSON, INI, XML) (, , . .)



? : . , , .



, StackOverflow



- , 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 ..





IoC- Unity, โ€” AutoFac, .



NetCore Microsoft.Extensions.DependencyInjection ServiceCollection, :



  • Singleton โ€”
  • Scoped โ€” , Http-
  • Transient โ€”


IServiceProvider, .



: 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.


Windows Forms.



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 . . .



: ASP.NET Core



โ€” , , , , HTTP .



: HTTP ASP.NET Core . Middleware. :



ASP.NET Core middleware pipeline



ASP.NET Core Filter Pipeline



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, , ), :





Workflow Foundation, . ?





? , , , ,

. : HTTP Rest like ,

( ) โ€” gRPC . โ€ฆ ( ) Web Forms.



UPD: Portatibility Analyzer.




All Articles