Skip to content

Commit 5ce1988

Browse files
committed
Changed the examples so I could use them in the article on the library
1 parent 53f9a2a commit 5ce1988

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

READMe.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public void ConfigureServices(IServiceCollection services)
2323

2424
Licence: MIT.
2525

26+
**See [this article](https://www.thereformedprogrammer.net/asp-net-core-fast-and-automatic-dependency-injection-setup/)
27+
for a bigger coverage of Microsoft DI and the application of this library in real applications.**
28+
2629
## Why have I written this extension?
2730

2831
There are two reasons:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
namespace Test
55
{
6-
public interface IMyOtherService { int MyInt { get; } }
6+
public interface IMyOtherService { string Result { get; } }
77
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33

44
namespace Test
55
{
6-
public interface IMyService { int MyInt { get; } }
6+
public interface IMyService
7+
{
8+
string IntToString(int num);
9+
}
710
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ namespace Test
55
{
66
public class MyOtherService : IMyOtherService
77
{
8-
public int MyInt { get; set; }
8+
public string Result { get; set; }
99
}
1010
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ namespace Test
55
{
66
public class MyService : IMyService, TestAutoRegisterDi.INestedMyService
77
{
8-
public int MyInt { get; set; }
8+
public string IntToString(int num)
9+
{
10+
return num.ToString();
11+
}
912
}
1013
}

Test/PublicServices/UseService.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/
2+
// Licensed under MIT licence. See License.txt in the project root for license information.
3+
4+
namespace Test
5+
{
6+
public class UseService
7+
{
8+
private readonly IMyService _service;
9+
10+
public UseService(IMyService service)
11+
{
12+
_service = service;
13+
}
14+
15+
public string CallService()
16+
{
17+
int i = 1; //... some calculation
18+
return _service.IntToString(i);
19+
}
20+
}
21+
}

Test/TestAutoRegisterDi.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ namespace Test
1414
{
1515
public class TestAutoRegisterDi
1616
{
17-
public interface INestedMyService {
18-
int MyInt { get; }
17+
public interface INestedMyService
18+
{
19+
string IntToString(int num);
1920
}
2021

21-
public class NestedMyService
22+
public class NestedMyService : INestedMyService
2223
{
23-
public int MyInt { get; set; }
24+
public string IntToString(int num)
25+
{
26+
return num.ToString();
27+
}
2428
}
2529

2630
[Fact]
@@ -34,7 +38,7 @@ public void TestRegisterAssemblyPublicNonGenericClasses()
3438

3539
//VERIFY
3640
//does not cotain nested class
37-
autoRegData.TypesToConsider.ShouldEqual( new []{typeof(MyOtherService), typeof(MyService), typeof(TestAutoRegisterDi) });
41+
autoRegData.TypesToConsider.ShouldEqual( new []{typeof(MyOtherService), typeof(MyService), typeof(UseService), typeof(TestAutoRegisterDi) });
3842
}
3943

4044
[Fact]
@@ -76,7 +80,7 @@ public void TestWhere()
7680
var service = new ServiceCollection();
7781

7882
//ATTEMP
79-
var autoRegData = service.RegisterAssemblyPublicNonGenericClasses(Assembly.GetExecutingAssembly())
83+
service.RegisterAssemblyPublicNonGenericClasses(Assembly.GetExecutingAssembly())
8084
.Where(x => x.Name == nameof(MyService))
8185
.AsPublicImplementedInterfaces();
8286

0 commit comments

Comments
 (0)