Skip to content

Instantly share code, notes, and snippets.

View matmalkowski's full-sized avatar

Maciej Małkowski matmalkowski

View GitHub Profile
@matmalkowski
matmalkowski / AttributeInjector.cs
Created June 18, 2018 09:07
Working with built-in dependency injection of ASP .NET Core - finding and adding to container
public static class AttributeInjector
{
public static void AddInjectionByAttribute(this IServiceCollection services)
{
RegisterWithAttribute(ref services, typeof(InjectableSingletonAttribute));
RegisterWithAttribute(ref services, typeof(InjectableTransientAttribute));
RegisterWithAttribute(ref services, typeof(InjectableScopedAttribute));
}
private static void RegisterWithAttribute(ref IServiceCollection services, Type injectableAttribute)
@matmalkowski
matmalkowski / Attributes.cs
Created June 18, 2018 08:51
Working with built-in dependency injection of ASP .NET Core - Attributes
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class InjectableTransientAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class InjectableScopedAttribute : Attribute
{
}
@matmalkowski
matmalkowski / Startup.cs
Last active June 18, 2018 08:58
Working with built-in dependency injection of ASP .NET Core - Startup.cs example
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseInMemoryDatabase()
);
// Add framework services.
services.AddMvc();
// Register application services.
version: '0.1.2-beta-{build}'
platform: Any CPU
configuration: Release
os: Visual Studio 2017
before_build:
- dotnet restore
- dotnet restore .\NetCoreTeamCity.Tests
after_build:
- dotnet pack ".\NetCoreTeamCity\NetCoreTeamCity.csproj" -c %CONFIGURATION% -o ..\artifacts
artifacts:
- path: artifacts\**\*.*
deploy:
provider: NuGet
api_key:
secure: Fec5HdqiA0Akjsvv03vBNhcc1bSEtrOBNfLTcP5tL6LM/s++ra9EltKovDC3Mn3x
skip_symbols: false
artifact: /.*\.nupkg/
param(
[string]
$ResultsFile,
[string]
$ResultsType = "mstest"
)
$ResultsFile = Resolve-Path $ResultsFile
$Url = "https://ci.appveyor.com/api/testresults/$ResultsType/$($env:APPVEYOR_JOB_ID)"
test_script:
- dotnet test ".\NetCoreTeamCity.Tests\NetCoreTeamCity.Tests.csproj" -c %CONFIGURATION% --logger:trx;LogFileName=tests-results01.xml
- ps: .\build\uploadtests.ps1 ".\NetCoreTeamCity.Tests\TestResults\tests-results01.xml"
version: '0.1.2-beta-{build}'
platform: Any CPU
configuration: Release
os: Visual Studio 2017
before_build:
- dotnet restore
- dotnet restore .\NetCoreTeamCity.Tests