Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Allow user to set CacheProvider (fixes #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarbettini committed Sep 2, 2016
1 parent 5da0428 commit c6f1d1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/Stormpath.Owin.Middleware/StormpathMiddleware.Initialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Stormpath.Owin.Middleware.Route;
using Stormpath.SDK;
using Stormpath.SDK.Application;
using Stormpath.SDK.Cache;
using Stormpath.SDK.Client;
using Stormpath.SDK.Directory;
using Stormpath.SDK.Http;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static StormpathMiddleware Create(StormpathOwinOptions options)

// Initialize and warm up SDK
options.Logger.Trace("Initializing and warming up SDK...", nameof(StormpathMiddleware));
var clientFactory = InitializeClient(options.Configuration, options.ConfigurationFileRoot, options.Logger);
var clientFactory = InitializeClient(options.Configuration, options.ConfigurationFileRoot, options.CacheProvider, options.Logger);

// Scope a client for our resolution steps below
options.Logger.Trace("Creating scoped ClientFactory...", nameof(StormpathMiddleware));
Expand Down Expand Up @@ -106,10 +107,10 @@ public static StormpathMiddleware Create(StormpathOwinOptions options)
handlerConfiguration);
}

private static IScopedClientFactory InitializeClient(object initialConfiguration, string configurationFileRoot, ILogger logger)
private static IScopedClientFactory InitializeClient(object initialConfiguration, string configurationFileRoot, ICacheProviderBuilder cacheProviderBuilder, ILogger logger)
{
// Construct base client
var baseClient = Clients.Builder()
var clientBuilder = Clients.Builder()
#if NET45
.SetHttpClient(HttpClients.Create().RestSharpClient())
#else
Expand All @@ -118,8 +119,14 @@ private static IScopedClientFactory InitializeClient(object initialConfiguration
.SetSerializer(Serializers.Create().JsonNetSerializer())
.SetConfiguration(initialConfiguration)
.SetConfigurationFileRoot(configurationFileRoot)
.SetLogger(logger)
.Build();
.SetLogger(logger);

if (cacheProviderBuilder != null)
{
clientBuilder.SetCacheProviderBuilder(cacheProviderBuilder);
}

var baseClient = clientBuilder.Build();

// Attempt to connect and prime the cache with ITenant
try
Expand Down
3 changes: 3 additions & 0 deletions src/Stormpath.Owin.Middleware/StormpathOwinOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Threading.Tasks;
using Stormpath.SDK.Logging;
using Stormpath.Owin.Abstractions;
using Stormpath.SDK.Cache;

namespace Stormpath.Owin.Middleware
{
Expand All @@ -34,6 +35,8 @@ public sealed class StormpathOwinOptions

public IViewRenderer ViewRenderer { get; set; }

public ICacheProviderBuilder CacheProvider { get; set; }

public Func<PreChangePasswordContext, CancellationToken, Task> PreChangePasswordHandler { get; set; }
= (ctx, ct) => TaskConstants.CompletedTask;

Expand Down
4 changes: 2 additions & 2 deletions test/Stormpath.Owin.UnitTest/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"Stormpath.Owin.Middleware": {
"target": "project",
"version": "1.1.0"
"version": "2.0.0-beta2"
},
"xunit": "2.1.0"
},
Expand All @@ -34,5 +34,5 @@
"tooling": {
"defaultNamespace": "Stormpath.Owin.UnitTest"
},
"version": "1.1.0"
"version": "2.0.0-beta2"
}

0 comments on commit c6f1d1c

Please sign in to comment.