AutoMapper Migrating from static API

后端 未结 4 1652
无人及你
无人及你 2020-12-05 05:08

https://github.com/AutoMapper/AutoMapper/wiki/Migrating-from-static-API

this change breaks my system.

Before update, I use:

===> Startup.cs



        
4条回答
  •  失恋的感觉
    2020-12-05 05:25

    Ben Walters: Dependency injection added a whole level of complexity to my legacy project that I just didn't want to deal with...

    HI

    Furthermore, you can apply the class alias using statement and no need to change the code, just change the using statement.

    Define a using directive and a using alias for a class: https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/keywords/using-directive#example-2

    --

    .Your class implementation for compatibility.

    namespace AutoMappers
    {
      public class Mapper
      {
        public static void Initialize(Action config)
        {
          ...
        }
      }
    }

    .Change "using AutoMapper" to "using Mapper = AutoMappers.Mapper".

    using Mapper = AutoMappers.Mapper; <-- using statement changed
    
    namespace ...
    {
      public class ...
      {
        public ...(...)
        {
          Mapper.Initialize(cfg => cfg.CreateMap()); <-- other code line kept originally

    --

提交回复
热议问题