You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: READMe.md
+79-29Lines changed: 79 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,24 @@ This [NuGet library](https://www.nuget.org/packages/NetCore.AutoRegisterDi/) con
4
4
5
5
I have written a simple version of AutoFac's `RegisterAssemblyTypes` method that works directly with Microsoft's DI provider. Here are an example of me using this with ASP.NET Core.
6
6
7
-
**Version 2 update**: New attributes for defining the `ServiceLifetime` of your classes, e.g. adding the `[RegisterAsScoped]` attribute to a class will mean its `ServiceLifetime` in the DI will be set to `Scoped`. *Added by Fedor Zhekov (GitHub @ZFi88)*.
7
+
**Version 2.0.0 update**: New attributes for defining the `ServiceLifetime` of your classes, e.g. adding the `[RegisterAsScoped]` attribute to a class will mean its `ServiceLifetime` in the DI will be set to `Scoped`. *Added by Fedor Zhekov (GitHub @ZFi88)*.
8
8
9
-
#### Example 1 - scan the calling assembly
9
+
**Version 2.1.0 update**: Added ability ignore an interface, plus added `ISerializable` interface to list of ignored interfaces and outputs results so that you can check it is registering the correct things.
2. An `Where` extensionmethod, whichallowsyoutofiltertheclassestobeconsidered.
70
+
3. An `IgnoreThisInterface<IMyInterface>` extensionmethodthatallowsyoutoaddaninterfacetobeignored. Thisallowsyoutostopaclassbeingregistered
71
+
4. The `AsPublicImplementedInterfaces` methodwhichfindsantinterfacesonaclassandregistersthoseinterfacesaspointingtotheclass. ItalsoreturnsalistofresultsthatallowsyoucheckwhatclasseshavebeenregisteredwiththeDIprovider.
-Youcanusemultiple `Where` methods. Theyhavean `&&` effect, e.g. thefollowingcodewouldregisteralltheclassesotherthan `Class1` and `Class2`:
100
+
101
+
```c#
102
+
service.RegisterAssemblyPublicNonGenericClasses()
103
+
.Where(c=>c.Name!="Class1"))
104
+
.Where(c=>c.Name!="Class2"))
105
+
.AsPublicImplementedInterfaces();
106
+
```
107
+
108
+
### 3. The `IgnoreThisInterface<IMyInterface>` method
109
+
110
+
Therearesomeinterfacesthatyoudon't want your classes to be registered, for instance `IDisposable` and `ISerializable` and these are already registered in NetCore.AutoRegisterDi. This means that no class will be registered against these two interfaces.
111
+
112
+
Youcanaddextrainterfacestotheinterfaceignorelistusingthe `IgnoreThisInterface<IMyInterface>`, e.g. thefollowingcodewouldaddthetwointerfaces `IMyInterface1` and `IMyInterface2` totheinterfaceignorelist.
113
+
114
+
```c#
115
+
service.RegisterAssemblyPublicNonGenericClasses()
116
+
.IgnoreThisInterface<IMyInterface1>()
117
+
.IgnoreThisInterface<IMyInterface2>()
118
+
.AsPublicImplementedInterfaces();
119
+
```
95
120
96
-
#### 3. The `AsPublicImplementedInterfaces` method
121
+
### 4. The `AsPublicImplementedInterfaces` method
97
122
98
123
The `AsPublicImplementedInterfaces` methodfindsanypublic, non-nestedinterfaces
0 commit comments