Closed MNF closed 1 year ago
I've added a paragraph to the FAQ page in the Wiki: https://github.com/mganss/HtmlSanitizer/wiki/Frequently-Asked-Questions
@mganss according to https://stackoverflow.com/questions/58065590/htmlsanitizer-asp-net-core-2-with-di
he .Net framework dependency injection is trying to inject the optional constructor parameters which results in empty AllowedTags and AllowAttributes collections.
Is the issue fixed?
If not, explicit default constructor implementation is required.
services.AddSingleton
Yes, the issue was fixed in #370
In https://github.com/mganss/HtmlSanitizer#usage or in https://github.com/mganss/HtmlSanitizer/wiki/Getting-Started#usage it will be good to mention that IHtmlSanitizer supports Dependency Injection and can be used as a singleton, e.g.
For example, if you are using asp.net core, in Startup AddSingleton
services.AddSingleton<IHtmlSanitizer>(_ => new HtmlSanitizer());
(From https://stackoverflow.com/questions/58065590/htmlsanitizer-asp-net-core-2-with-di)
and use constructor dependency injection to pass htmlSanitizer to your class