mganss / HtmlSanitizer

Cleans HTML to avoid XSS attacks
MIT License
1.52k stars 198 forks source link

Mention Dependency Injection support in Readme or in Wiki #431

Closed MNF closed 1 year ago

MNF commented 1 year ago

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

mganss commented 1 year ago

I've added a paragraph to the FAQ page in the Wiki: https://github.com/mganss/HtmlSanitizer/wiki/Frequently-Asked-Questions

michael-freidgeim-webjet commented 1 year ago

@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(_ => new HtmlSanitizer());

mganss commented 1 year ago

Yes, the issue was fixed in #370