-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to NET6, implicit usings and file scoped namespaces; fix CodeQL (
#80)
- Loading branch information
Showing
49 changed files
with
1,262 additions
and
1,348 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
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
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
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
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 |
---|---|---|
|
@@ -31,17 +31,13 @@ jobs: | |
steps: | ||
- name: Checkout source | ||
uses: actions/checkout@v3 | ||
- name: Setup .NET Core 3.1 SDK | ||
- name: Setup .NET Core SDKs | ||
uses: actions/setup-dotnet@v2 | ||
with: | ||
dotnet-version: '3.1.x' | ||
source-url: https://nuget.pkg.github.com/sungam3r/index.json | ||
env: | ||
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
- name: Setup .NET Core 5.0 SDK | ||
uses: actions/setup-dotnet@v2 | ||
with: | ||
dotnet-version: '5.0.x' | ||
dotnet-version: | | ||
3.1.x | ||
5.0.x | ||
6.0.102 | ||
source-url: https://nuget.pkg.github.com/sungam3r/index.json | ||
env: | ||
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
|
@@ -52,8 +48,7 @@ jobs: | |
if: ${{ startsWith(matrix.os, 'ubuntu') }} | ||
working-directory: src | ||
run: | | ||
dotnet tool install -g dotnet-format --version 6.0.243104 --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json | ||
dotnet format --check -v diag --fix-style warn --fix-analyzers warn || (echo "Run 'dotnet format' to fix formatting issues" && exit 1) | ||
dotnet format --no-restore --verify-no-changes --severity warn || (echo "Run 'dotnet format' to fix issues" && exit 1) | ||
- name: Build solution [Release] | ||
working-directory: src | ||
run: dotnet build --no-restore -c Release | ||
|
@@ -67,7 +62,7 @@ jobs: | |
if: ${{ startsWith(matrix.os, 'ubuntu') }} | ||
uses: codecov/[email protected] | ||
with: | ||
files: .coverage/SteroidsDI.Tests/coverage.netcoreapp3.1.opencover.xml | ||
files: .coverage/SteroidsDI.Tests/coverage.net6.opencover.xml | ||
|
||
buildcheck: | ||
needs: | ||
|
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,50 +1,47 @@ | ||
using System; | ||
namespace Example; | ||
|
||
namespace Example | ||
public interface IEntryPoint | ||
{ | ||
public interface IEntryPoint | ||
int DoSomethingImportant(); | ||
} | ||
|
||
public class EntryPoint : IEntryPoint | ||
{ | ||
//private IRepository _repository; - this is an example of what you wanted to do but got the error below | ||
private readonly Defer<IRepository> _repository1; | ||
private readonly Func<IRepository> _repository2; | ||
private readonly IRepositoryFactory _repoFactory; | ||
|
||
public EntryPoint( | ||
// Error while validating the service descriptor 'ServiceType: Example.IEntryPoint Lifetime: Singleton ImplementationType: Example.EntryPoint': | ||
// Cannot consume scoped service 'Example.IRepository' from singleton 'Example.IEntryPoint'. | ||
//IRepository repository | ||
Defer<IRepository> repository1, | ||
Func<IRepository> repository2, | ||
IRepositoryFactory repoFactory) | ||
{ | ||
int DoSomethingImportant(); | ||
_repository1 = repository1; | ||
_repository2 = repository2; | ||
_repoFactory = repoFactory; | ||
} | ||
|
||
public class EntryPoint : IEntryPoint | ||
public int DoSomethingImportant() | ||
{ | ||
//private IRepository _repository; - this is an example of what you wanted to do but got the error below | ||
private readonly Defer<IRepository> _repository1; | ||
private readonly Func<IRepository> _repository2; | ||
private readonly IRepositoryFactory _repoFactory; | ||
|
||
public EntryPoint( | ||
// Error while validating the service descriptor 'ServiceType: Example.IEntryPoint Lifetime: Singleton ImplementationType: Example.EntryPoint': | ||
// Cannot consume scoped service 'Example.IRepository' from singleton 'Example.IEntryPoint'. | ||
//IRepository repository | ||
Defer<IRepository> repository1, | ||
Func<IRepository> repository2, | ||
IRepositoryFactory repoFactory) | ||
{ | ||
_repository1 = repository1; | ||
_repository2 = repository2; | ||
_repoFactory = repoFactory; | ||
} | ||
// All 3 APIs return the same instance | ||
var repo1 = _repository1.Value; | ||
var repo2 = _repository2(); | ||
var repo3 = _repoFactory.GetPersonsRepo(); | ||
|
||
public int DoSomethingImportant() | ||
{ | ||
// All 3 APIs return the same instance | ||
var repo1 = _repository1.Value; | ||
var repo2 = _repository2(); | ||
var repo3 = _repoFactory.GetPersonsRepo(); | ||
|
||
if (!ReferenceEquals(repo1, repo2) || !ReferenceEquals(repo1, repo3)) | ||
throw new InvalidOperationException(); | ||
|
||
var persons = repo1.GetPersons(); | ||
if (!ReferenceEquals(repo1, repo2) || !ReferenceEquals(repo1, repo3)) | ||
throw new InvalidOperationException(); | ||
|
||
foreach (var person in persons) | ||
{ | ||
Console.WriteLine($"{person.Name} ({person.Age})"); | ||
} | ||
var persons = repo1.GetPersons(); | ||
|
||
return persons.Count; | ||
foreach (var person in persons) | ||
{ | ||
Console.WriteLine($"{person.Name} ({person.Age})"); | ||
} | ||
|
||
return persons.Count; | ||
} | ||
} |
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,8 +1,7 @@ | ||
namespace Example | ||
namespace Example; | ||
|
||
public interface IRepositoryFactory | ||
{ | ||
public interface IRepositoryFactory | ||
{ | ||
// method name does not matter | ||
IRepository GetPersonsRepo(); | ||
} | ||
// method name does not matter | ||
IRepository GetPersonsRepo(); | ||
} |
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,9 +1,8 @@ | ||
namespace Example | ||
namespace Example; | ||
|
||
public class Person | ||
{ | ||
public class Person | ||
{ | ||
public string? Name { get; set; } | ||
public string? Name { get; set; } | ||
|
||
public int Age { get; set; } | ||
} | ||
public int Age { get; set; } | ||
} |
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,38 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
namespace Example; | ||
|
||
namespace Example | ||
public interface IRepository | ||
{ | ||
public interface IRepository | ||
List<Person> GetPersons(); | ||
} | ||
|
||
public class Repository : IRepository | ||
{ | ||
public Repository() | ||
{ | ||
List<Person> GetPersons(); | ||
Console.WriteLine("Initializing repository"); | ||
Thread.Sleep(3000); | ||
Console.WriteLine("Repository initialized"); | ||
} | ||
|
||
public class Repository : IRepository | ||
public List<Person> GetPersons() | ||
{ | ||
public Repository() | ||
return new List<Person> | ||
{ | ||
Console.WriteLine("Initializing repository"); | ||
Thread.Sleep(3000); | ||
Console.WriteLine("Repository initialized"); | ||
} | ||
|
||
public List<Person> GetPersons() | ||
{ | ||
return new List<Person> | ||
new Person | ||
{ | ||
Name = "Chip", | ||
Age = 31 | ||
}, | ||
new Person | ||
{ | ||
new Person | ||
{ | ||
Name = "Chip", | ||
Age = 31 | ||
}, | ||
new Person | ||
{ | ||
Name = "Dale", | ||
Age = 32 | ||
} | ||
}; | ||
} | ||
Name = "Dale", | ||
Age = 32 | ||
} | ||
}; | ||
} | ||
} |
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,18 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Example | ||
{ | ||
[Route("api/[controller]")] | ||
public class PersonsController : ControllerBase | ||
{ | ||
private readonly IEntryPoint _entry; | ||
namespace Example; | ||
|
||
public PersonsController(IEntryPoint entry) | ||
{ | ||
_entry = entry; | ||
} | ||
[Route("api/[controller]")] | ||
public class PersonsController : ControllerBase | ||
{ | ||
private readonly IEntryPoint _entry; | ||
|
||
[HttpGet] | ||
public object Get() => new { Count = _entry.DoSomethingImportant() }; | ||
public PersonsController(IEntryPoint entry) | ||
{ | ||
_entry = entry; | ||
} | ||
|
||
[HttpGet] | ||
public object Get() => new { Count = _entry.DoSomethingImportant() }; | ||
} |
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,14 +1,10 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
namespace Example; | ||
|
||
namespace Example | ||
public class Program | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) => CreateHostBuilder(args).Build().Run(); | ||
public static void Main(string[] args) => CreateHostBuilder(args).Build().Run(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()); | ||
} | ||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()); | ||
} |
Oops, something went wrong.