-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: improve constructor resolution in aspnet core dependency injection
- Loading branch information
1 parent
061ee04
commit 74615ce
Showing
4 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
|
||
namespace LazyCache.UnitTests | ||
{ | ||
public class AspNetCoreTests | ||
{ | ||
[Test] | ||
public void CanResolveCacheFromServiceCollectionAsRequiredService() | ||
{ | ||
var container = new ServiceCollection(); | ||
container.AddLazyCache(); | ||
var provider = container.BuildServiceProvider(); | ||
|
||
var cache = provider.GetRequiredService<IAppCache>(); | ||
var result = cache?.GetOrAdd("key", () => new object()); | ||
|
||
cache.Should().NotBeNull(); | ||
result.Should().NotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void CanResolveCacheFromServiceCollectionAsService() | ||
{ | ||
var container = new ServiceCollection(); | ||
container.AddLazyCache(); | ||
var provider = container.BuildServiceProvider(); | ||
|
||
var cache = provider.GetService<IAppCache>(); | ||
var result = cache?.GetOrAdd("key", () => new object()); | ||
|
||
cache.Should().NotBeNull(); | ||
result.Should().NotBeNull(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters