Skip to content

Commit

Permalink
feat: add LazyCache.AspNetCore DI pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
alastairtree committed Mar 3, 2018
1 parent 8aab626 commit 45648a6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LazyCache.AspNetCore\LazyCache.AspNetCore.csproj" />
<ProjectReference Include="..\LazyCache\LazyCache.csproj" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions CacheDatabaseQueriesApiSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public void ConfigureServices(IServiceCollection services)
// register the database
services.AddDbContext<DbTimeContext>(options => options.UseSqlServer(connection));

// add a single instance of the cache (transiant would also work as default cache is shared)
services.AddSingleton<IAppCache, CachingService>();
// Register IAppCache as a singleton CachingService
services.AddLazyCache();

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
24 changes: 24 additions & 0 deletions LazyCache.AspNetCore/LazyCache.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>LazyCache</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0</Version>
<Authors>https://github.com/alastairtree</Authors>
<Company>https://github.com/alastairtree</Company>
<Description>ServiceCollection regististrations fopr LazyCache to initialise the depndency injection</Description>
<Copyright>Copyright 2014 - 2018 Alastair Crabtree</Copyright>
<PackageLicenseUrl>https://github.com/alastairtree/LazyCache/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/alastairtree/LazyCache</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/alastairtree/LazyCache/master/artwork/logo-128.png</PackageIconUrl>
<RepositoryUrl>https://github.com/alastairtree/LazyCache</RepositoryUrl>
<PackageTags>LazyCache DependecyInjection ServiceCollection SingleTon Transient</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="microsoft.extensions.dependencyinjection.abstractions" Version="2.0.0" />
<ProjectReference Include="..\LazyCache\LazyCache.csproj" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions LazyCache.AspNetCore/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using LazyCache;

// ReSharper disable once CheckNamespace - MS guidelines say put DI registration in this NS
namespace Microsoft.Extensions.DependencyInjection
{
public static class LazyCacheServiceRegistration
{
public static IServiceCollection AddLazyCache(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));

services.AddSingleton<IAppCache, CachingService>();

return services;
}

public static IServiceCollection AddLazyCache(this IServiceCollection services, Func<IServiceProvider, CachingService> implmentationFactory)
{
if (services == null) throw new ArgumentNullException(nameof(services));
if (implmentationFactory == null) throw new ArgumentNullException(nameof(implmentationFactory));

services.AddSingleton<IAppCache>(implmentationFactory);

return services;
}
}
}
10 changes: 8 additions & 2 deletions LazyCache.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2024
VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LazyCache", "LazyCache\LazyCache.csproj", "{E6A1EF20-94AD-4A1C-9A89-3B2FA8AD8EC7}"
EndProject
Expand All @@ -17,7 +17,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "info", "info", "{81C0E096-5
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{335BA426-C839-4996-8476-F3EE4056C40E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CacheDatabaseQueriesApiSample", "CacheDatabaseQueriesApiSample\CacheDatabaseQueriesApiSample.csproj", "{5D6A88DD-230C-4057-B8EB-A987FF4F29DB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CacheDatabaseQueriesApiSample", "CacheDatabaseQueriesApiSample\CacheDatabaseQueriesApiSample.csproj", "{5D6A88DD-230C-4057-B8EB-A987FF4F29DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LazyCache.AspNetCore", "LazyCache.AspNetCore\LazyCache.AspNetCore.csproj", "{A7B07002-29F5-4463-8CA7-097C337337A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -37,6 +39,10 @@ Global
{5D6A88DD-230C-4057-B8EB-A987FF4F29DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D6A88DD-230C-4057-B8EB-A987FF4F29DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D6A88DD-230C-4057-B8EB-A987FF4F29DB}.Release|Any CPU.Build.0 = Release|Any CPU
{A7B07002-29F5-4463-8CA7-097C337337A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7B07002-29F5-4463-8CA7-097C337337A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7B07002-29F5-4463-8CA7-097C337337A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7B07002-29F5-4463-8CA7-097C337337A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 45648a6

Please sign in to comment.