Skip to content

Instantly share code, notes, and snippets.

@daanl
Created December 8, 2012 22:56
Show Gist options
  • Save daanl/4242380 to your computer and use it in GitHub Desktop.
Save daanl/4242380 to your computer and use it in GitHub Desktop.
using System.Web.Mvc;
using UI.Web.Cultures;
using UI.Web.Localization;
namespace UI.Web.Views
{
/// <summary>
/// Custom web view page
/// Adds CultureService, LocalizationService and Localize to the views
/// </summary>
/// <typeparam name="TModel">dynamic</typeparam>
public abstract class CustomWebViewPage<TModel> : WebViewPage<TModel>
{
/// <summary>
/// Localization service field used for caching
/// </summary>
private ILocalizeService _localizeService;
/// <summary>
/// Culture service field used for caching
/// </summary>
private ICultureService _cultureService;
/// <summary>
/// Culture service
/// </summary>
public ICultureService CultureService
{
get
{
// get culture service if its not set
if (_cultureService == null)
{
_cultureService = Resolve<ICultureService>();
}
return _cultureService;
}
}
/// <summary>
/// Localization Service
/// </summary>
private ILocalizeService LocalizeService
{
get
{
// get localizeService if its not set
if (_localizeService == null)
{
_localizeService = Resolve<ILocalizeService>();
}
return _localizeService;
}
}
/// <summary>
/// Localizes string with localization service
/// </summary>
/// <param name="value">Value you want to localize</param>
/// <returns>Localized value</returns>
public string Localize(string value)
{
return LocalizeService.Localize(value);
}
// Shortcut to resolver
private T Resolve<T>()
{
return DependencyResolver.Current.GetService<T>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment