Skip to content

Commit

Permalink
Added GitVersion to the repo, and modified the build yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten Kools committed Dec 19, 2018
1 parent d65b67e commit b90691a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 34 deletions.
3 changes: 3 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
branches: {}
ignore:
sha: []
60 changes: 59 additions & 1 deletion README.md
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);
}
}
```
19 changes: 16 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
version: '{build}'
pull_requests:
do_not_increment_build_number: true

install:
- choco install gitversion.portable -pre -y

assembly_info:
patch: false

nuget:
disable_publish_on_pr: true

before_build:
- cmd: dotnet restore .\src\SpecFlow.GenericContainer.sln
- cmd: gitversion /l console /output buildserver /updateAssemblyInfo
- cmd: dotnet build .\src\SpecFlow.GenericContainer.sln -c Release -v q --no-restore /nologo
- cmd: dotnet pack .\src\SpecFlow.GenericContainer.sln -c Release -o .\artifacts --include-symbols --no-build --no-restore /nologo -p:PackageVersion="%GitVersion_NuGetVersion%"

build_script:
- ps: .\build.ps1
test: off

artifacts:
- path: '.\artifacts\**\*.nupkg'
name: NuGet

deploy:
- provider: NuGet
name: production
Expand Down
30 changes: 0 additions & 30 deletions build.ps1

This file was deleted.

0 comments on commit b90691a

Please sign in to comment.