It’s been a long time coming, but Heroic.AutoMapper 5.0 is now live on NuGet, and with it, support for .NET Standard (and therefore .NET Core)!

Breaking Change

This is a breaking change from previous versions. If you are upgrading from 4.0.0, you will need to make a small change.

Previous versions used WebActivatorEx to automatically wire things up for you, usually with no code changes on your part. That’s no longer the case with 5.0.0.

Instead, you will need to explicitly call one of HeroicAutoMapperConfigurator‘s configuration methods, like so:

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies<HomeController>();
        }
    }

But there’s a reason for that change…

Heroic.AutoMapper Now Supports Everything!

You can now use Heroic.AutoMapper with ASP.NET MVC 5, ASP.NET Web API, ASP.NET Core, console applications… whatever you want. There is no longer any dependency on ASP.NET or any of its infrastructure.

If you want to use Heroic.AutoMapper with ASP.NET Core, you can call it from your Startup class, like so:

using Heroic.AutoMapper;

namespace YourNamespace
{
    public class Startup
    {
        //.. snip

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());

            app.UseAuthentication();

            app.UseMvc();

			HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies<WidgetModel>();
        }
    }
}

Want to use it in a console app? You can use this:

using Heroic.AutoMapper;

public class Program 
{
	public static void Main() 
	{
		HeroicAutoMapperConfigurator.LoadMapsFromCallerAndReferencedAssemblies();

		Console.WriteLine("All set!");
	}
}

Give It a Shot!

Installing this new version is easy:

dotnet add package Heroic.AutoMapper --version 5.0.0

Or

Install-Package Heroic.AutoMapper -Version 5.0.0

If you run into any problems, please let me know on the Github repo!