Exemple #1
0
    /// <summary>
    /// Adds MVC view and data annotations localization services to the application.
    /// </summary>
    /// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
    /// <param name="localizationOptionsSetupAction">An action to configure
    /// the <see cref="LocalizationOptions"/>. Can be <c>null</c>.</param>
    /// <param name="format">The view format for localized views.</param>
    /// <param name="dataAnnotationsLocalizationOptionsSetupAction">An action to configure
    /// the <see cref="MvcDataAnnotationsLocalizationOptions"/>. Can be <c>null</c>.</param>
    /// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
    /// <remarks>
    /// Adding localization also adds support for views via
    /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
    /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
    /// </remarks>
    public static IMvcCoreBuilder AddMvcLocalization(
        this IMvcCoreBuilder builder,
        Action <LocalizationOptions>?localizationOptionsSetupAction,
        LanguageViewLocationExpanderFormat format,
        Action <MvcDataAnnotationsLocalizationOptions>?dataAnnotationsLocalizationOptionsSetupAction)
    {
        if (builder == null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        return(builder
               .AddViewLocalization(format, localizationOptionsSetupAction)
               .AddDataAnnotationsLocalization(dataAnnotationsLocalizationOptionsSetupAction));
    }