-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GitVersion to the repo, and modified the build yaml
- Loading branch information
Maarten Kools
committed
Dec 19, 2018
1 parent
d65b67e
commit b90691a
Showing
4 changed files
with
78 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
branches: {} | ||
ignore: | ||
sha: [] |
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 |
---|---|---|
@@ -1,2 +1,60 @@ | ||
# SpecFlow.GenericInjector | ||
# SpecFlow.GenericContainer | ||
A SpecFlow plugin that provides a generic way to implement a custom DI container | ||
|
||
# Usage | ||
1. Create a class that implements the `IGenericContainer` interface and wraps your DI container. | ||
2. Create a class that contains a static function with the `ScenarioDependenciesAttribute` that configures the container, and returns your `IGenericContainer` implementation. | ||
|
||
# Example | ||
## SimpleInjector | ||
```csharp | ||
public class SimpleInjectorContainer : IGenericContainer | ||
{ | ||
private readonly Container _container; | ||
|
||
public SimpleInjectorContainer(Container container) | ||
{ | ||
_container = container; | ||
} | ||
|
||
public void Register<TService>(Func<TService> instanceCreator) | ||
where TService : class | ||
{ | ||
_container.Register(instanceCreator); | ||
} | ||
|
||
public object Resolve(Type bindingType) | ||
{ | ||
return _container.GetInstance(bindingType); | ||
} | ||
|
||
public TService Resolve<TService>() | ||
where TService : class | ||
{ | ||
return _container.GetInstance<TService>(); | ||
} | ||
} | ||
``` | ||
```csharp | ||
public static class Dependencies | ||
{ | ||
[ScenarioDependencies] | ||
public static IGenericContainer CreateContainer() | ||
{ | ||
var container = new Container(); | ||
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); | ||
container.Options.DefaultLifestyle = Lifestyle.Singleton; | ||
|
||
// Add your registrations here | ||
foreach (var type in typeof(Dependencies).Assembly | ||
.GetTypes() | ||
.Where(t => Attribute.IsDefined(t, typeof(BindingAttribute)))) | ||
{ | ||
container.Register(type); | ||
} | ||
|
||
return new SimpleInjectorContainer(container); | ||
} | ||
} | ||
``` |
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