Open Closed

Getting ILocalizationManager injected into AbpWebViewPage<T> #63


0
langman66 created

I'm using ABP framework in a MVC and SPA application. The front-end application is MVC to benefit from SEO.

My application supports multiple languages (thanks to Abp awesome framework).

What I need to do is build a dynamic header menu for different language supported on the _Layout.cshtml base razor layout page.

In my _Layout.cshtml, I split my top menu into a Partial.

@Html.Partial("_TopBar")

Every page uses the _Layout.cshtml for their base template (Index.cshtml, Contact.cshtml, etc.).

Below is my _TopBar.cshtml partial page.

Question:

In my base MVC page public abstract class CaptureWebViewPageBase

I'm trying to use Property injection to get an public ILocalizationManager LocalizationManager { get; set; } but this object is not being set.

If I use constructor injection, then I get compile errors telling me "CaptureWebViewPageBase

How can I inject the a ILocalizationManager into this page or am I doing this totally the wrong way?

Thanks so much for the guidance.

        <div class="col-md-6 col-sm-6 additional-nav">
            <ul class="list-unstyled list-inline pull-right">

                @using Microsoft.AspNet.Identity
                @if (Request.IsAuthenticated)
                {
                    <li>@Html.ActionLink(L("MyAccount"), "Dashboard", "App")</li>
                    <li>@Html.ActionLink(L("Logout"), "Logout", "Account", routeValues: null, htmlAttributes: new { id = "logoutForm", target = "_self" })</li>
                }
                else
                {
                    <li class="dropdown dropdown-language">
                        <a class="dropdown-toggle" dropdown-menu-hover data-toggle="dropdown" data-close-others="true">
                            <i></i>
                            <span class="langname">@L(@CurrentLanguage)  </span>
                            <i class="fa fa-angle-down"></i>
                        </a>
                                                    
                        <ul class="dropdown-menu dropdown-menu-default">
                                @foreach (var language in Languages)
                                {
                                    <li class="active">
                                        <a href="/AbpLocalization/ChangeCulture?cultureName=@language.Name">
                                            <i class="@language.Icon"></i> @L(language.DisplayName)
                                        </a>
                                    </li>
                                }                                
                        </ul>

                    </li>

                    <li>
                        @Html.ActionLink(@L("Login"), "Login", "Account")
                    </li>
                }

            </ul>
        </div>
        
    </div>
</div>

2 Answer(s)
  • 0
    langman66 created

    I ended up putting this in my constructor protected CaptureWebViewPageBase(){

            if (LocalizationManager == null)
            {
                LocalizationManager = IocManager.Instance.Resolve<ILocalizationManager>();                
            }
    
                Languages = LocalizationManager.GetAllLanguages();
                CurrentLanguage = LocalizationManager.CurrentLanguage;
    

    }

    Still not sure if this is the best approach, but it works for now :-)

  • 0
    hikalkan created

    This is the only option since we can not inject objects to views.