Closed Misiu closed 1 year ago
I think this is better suited for StackOverflow.
@lbargaoanu thank you for a quick reply. I searched StackOverflow before I asked the question (feature request) here. Most answers are similar to this one https://stackoverflow.com/a/73882676/965722 (btw it's your answer).
My use case is very simple: I need to log errors when doing deserialization inside mapExpression. I can't use DI (because it is not allowed in Profiles) and I can't use custom Value and Type Converters with ProjectTo.
DI in Profiles is explicitly discouraged and not supported. The best you can do is use static service location. At least then you'll know exactly what instance of your logger is getting used.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I have a project in .NET7. I'm adding AutoMapper using
services.AddAutoMapper(typeof(Bootstrap));
Everything works fine, I'm able to use ProjectTo with Entity Framework.I have a very complex mapper (at least for me) for two objects that involve XML deserialization and JSON deserialization.
For now, I'm using Debug.WriteLine to write errors about bad JSON and deserialization errors (I'm loading that data from an external system and it might be corrupted, I have no control over it), but I'd like to use a proper logger.
ProjectTo currently can't work with DI (https://github.com/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/113#issuecomment-524421715) and according to docs (https://docs.automapper.org/en/stable/Queryable-Extensions.html#supported-mapping-options) I can't create a Type or a Value converter.
So I'm asking to add support for DI in Profiles, this way I would be able to inject Logger and pass it the needed functions or allow using Value and/or Type converters when using ProjectTo.
Not sure if this is the correct place for this question, if not please transfer this issue.