Skip to content

Commit

Permalink
Merge pull request #232 from mikhail-syvachenko-syzygy/feature/add-op…
Browse files Browse the repository at this point in the history
…timizely-setup

feat: enable inner caching replacement for DbLocalization Optimizely registration with new DbLocalizationConfigurationContext
  • Loading branch information
valdisiljuconoks authored Oct 6, 2024
2 parents 8f1f16a + defadbd commit 3b90e76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using DbLocalizationProvider.Cache;

namespace DbLocalizationProvider.EPiServer;

/// <summary>
/// Configuration context for DbLocalizationProvider.EPiServer.
/// </summary>
public class DbLocalizationConfigurationContext
{
/// <summary>
/// Allows to override internal cache implementation, if problems with default EPiServer implementation arise.
/// </summary>
public ICache InnerCache { get; set; } = new EPiServerCache();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Valdis Iljuconoks. All rights reserved.
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information

using System;
using System.Globalization;
using System.Linq;
using DbLocalizationProvider.AspNetCore;
Expand All @@ -23,10 +24,15 @@ public static class IServiceCollectionExtensions
/// Adds Optimizely support for DbLocalizationProvider.
/// </summary>
/// <param name="builder">Provider builder interface (to capture context and service collection).</param>
/// <param name="setup">If required, modify configurations using the <see cref="DbLocalizationConfigurationContext"/></param>
/// <returns>Service collection to support fluent API.</returns>
public static IDbLocalizationProviderBuilder AddOptimizely(this IDbLocalizationProviderBuilder builder)
public static IDbLocalizationProviderBuilder AddOptimizely(this IDbLocalizationProviderBuilder builder, Action<DbLocalizationConfigurationContext>? setup = null)
{
builder.Context._baseCacheManager.SetInnerManager(new EPiServerCache());
var configContext = new DbLocalizationConfigurationContext();

setup?.Invoke(configContext);

builder.Context._baseCacheManager.SetInnerManager(configContext.InnerCache);

builder.Services.AddTransient<IResourceTypeScanner, LocalizedCategoryScanner>();

Expand Down

0 comments on commit 3b90e76

Please sign in to comment.