Base solution for your next web application
Open Closed

how about the L function use Extension Methods #2016


User avatar
0
marklin created

now:

new MenuItemDefinition(
                        "Home",
                        L("HomePage"),  // DisplayName 
                        url: "",
                        icon: "fa fa-home",
                        requiresAuthentication: true
                        )

after use Extension Methods

new MenuItemDefinition(
                        "Home",
                        "HomePage",   //remove the L function
                        url: "",
                        icon: "fa fa-home",
                        requiresAuthentication: true
                        )

And

this.DisplayName = displayName.toLocalLanguage();

1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    There are 2 problems with this code:

    1. It's not explicit if given string will be localized or not.
    2. Extension methods are static. So, we can not resolve ILocalizationManager (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Localization#DocInServer">http://www.aspnetboilerplate.com/Pages/ ... ocInServer</a>) from dependency injection. We shouldn't use IocManager.Instance (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection#DocIocHelper">http://www.aspnetboilerplate.com/Pages/ ... cIocHelper</a>) since it breaks testability.