AutoMapper / AutoMapper.Extensions.Microsoft.DependencyInjection

MIT License
258 stars 79 forks source link

Update Documentation #145

Closed json0007 closed 4 years ago

json0007 commented 4 years ago

This is less than an issue than a recommendation. I was experiencing the same issue as this guy.

https://github.com/AutoMapper/AutoMapper/issues/2825

I was completely thrown for a loop when experiencing this issue. I had all my DI components registered correctly, or so I thought. After a few hours poking around I finally discovered you need to pass a list of profileAssemblyMarkerTypes like so.

        services.AddAutoMapper(config => {
            config.AddProfile<MyMappingProfile>();
        }, new List<Type> { typeof(MyConverter)});

Now your explaination was correct. It was a DI configuration problem. However, my issue is that your documentation makes no mention of this at all here: https://docs.automapper.org/en/stable/Custom-type-converters.html?highlight=ITypeConverter#custom-type-converters .

There is a brief explanation found here of profile assembly types at the beginning of the DI section, but makes no mention of what these are or what they are used for or when they are needed https://docs.automapper.org/en/stable/Dependency-injection.html

Now I just want to say I appreciate everything you do. Automapper is a great tool that I use in every .net project I work on. I am just asking you to please update your documentation to be more clear on the steps needed to use ITypeConverter or other components in your software. The only way to figure this out was to dig through your source code and find why the issue was occurring, then dig through your service extension methods to see if there was a way to fix it. That could have all been avoided with a brief one liner stating "your will need to register your typeconverter by passing it into the service extension as an assembly like so ..."

Lastly, I might add that I find the notion of simply passing in a list of assemblies counter intuitive. You really should have builder returned by your service extension where you can have methods that add such pieces. For example they can be used like this:

services.AddAutoMapper(config => config.AddProfile\<MyProfile>) .AddTypeConverter\<MyTypeConverter>() .AddValueConverter\<MyValueConverter>();

This would be a lot more intuitive than just passing in a list of assemblies to an extension method with no xml documentation comments that can explain what the parameter is even used for. Thanks for listening

lbargaoanu commented 4 years ago

A PR is welcome.

github-actions[bot] commented 3 years ago

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.