Automapper on Asp.net mvc 4.8

800 views
Skip to first unread message

Mihir Ranade

unread,
Jul 28, 2021, 1:56:55 PM7/28/21
to AutoMapper-users
I spent 3 hours trying to get this thing working. The documentation doesnt help as theres nothing mentioned for non Asp.net core applications. All the stackoverflow posts are for things that are deprecated. Can someone provide me a good way to register and use Automapper in my controller? 

I tried a bunch of different things but couldnt understand how to do it. 

Thanks. 

Jimmy Bogard

unread,
Jul 28, 2021, 2:12:20 PM7/28/21
to automapper-users
Non .NET Core applications? Do you have a ServiceCollection thingy to do services.AddAutoMapper?

ASP.NET Core/.NET Core/SDK-style projects are all I use these days.
--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/automapper-users/bdc22247-d1f5-48d1-b8a5-488111d26399n%40googlegroups.com.

Mihir Ranade

unread,
Jul 28, 2021, 2:15:08 PM7/28/21
to AutoMapper-users
It's .Net 4.8 project. I just have the global.asax file. I did add this to my App_start function in Global.asax.cs file

var config = new MapperConfiguration(cfg => cfg.CreateMap<Order, OrderDto>());
var mapper = new Mapper(config); 

 but then what? How do I get  the reference in the controller is what I am confused about

Jimmy Bogard

unread,
Jul 28, 2021, 2:53:02 PM7/28/21
to automapper-users
Well, however you want really. It's no different than how you get access to any other object in your application in your controller. Are you using dependency injection or not, that sort thing. You can make a static field or whatever. It's up to you.
Reply all
Reply to author
Forward
0 new messages