-
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.
Merge pull request #10 from futurum-dev/feature/registration-generic-…
…attributes SourceGenerator - Registration
- Loading branch information
Showing
19 changed files
with
249 additions
and
26 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
6 changes: 6 additions & 0 deletions
6
.../Futurum.Microsoft.Extensions.DependencyInjection.Sample/AutomaticScopedGenericService.cs
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,6 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
[RegisterAsScoped<IService2>] | ||
public class AutomaticScopedGenericService : IService1, IService2 | ||
{ | ||
} |
2 changes: 1 addition & 1 deletion
2
sample/Futurum.Microsoft.Extensions.DependencyInjection.Sample/AutomaticScopedService.cs
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,6 +1,6 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
[RegisterAsScoped] | ||
public class AutomaticScopedService : IService | ||
public class AutomaticScopedService : IService1 | ||
{ | ||
} |
6 changes: 6 additions & 0 deletions
6
...turum.Microsoft.Extensions.DependencyInjection.Sample/AutomaticSingletonGenericService.cs
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,6 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
[RegisterAsSingleton<IService2>] | ||
public class AutomaticSingletonGenericService : IService1, IService2 | ||
{ | ||
} |
2 changes: 1 addition & 1 deletion
2
sample/Futurum.Microsoft.Extensions.DependencyInjection.Sample/AutomaticSingletonService.cs
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,6 +1,6 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
[RegisterAsSingleton] | ||
public class AutomaticSingletonService : IService | ||
public class AutomaticSingletonService : IService1 | ||
{ | ||
} |
6 changes: 6 additions & 0 deletions
6
...turum.Microsoft.Extensions.DependencyInjection.Sample/AutomaticTransientGenericService.cs
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,6 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
[RegisterAsTransient<IService2>] | ||
public class AutomaticTransientGenericService : IService1, IService2 | ||
{ | ||
} |
2 changes: 1 addition & 1 deletion
2
sample/Futurum.Microsoft.Extensions.DependencyInjection.Sample/AutomaticTransientService.cs
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,6 +1,6 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
[RegisterAsTransient] | ||
public class AutomaticTransientService : IService | ||
public class AutomaticTransientService : IService1 | ||
{ | ||
} |
2 changes: 1 addition & 1 deletion
2
...ns.DependencyInjection.Sample/IService.cs → ...s.DependencyInjection.Sample/IService1.cs
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,5 +1,5 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
public interface IService | ||
public interface IService1 | ||
{ | ||
} |
5 changes: 5 additions & 0 deletions
5
sample/Futurum.Microsoft.Extensions.DependencyInjection.Sample/IService2.cs
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,5 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
public interface IService2 | ||
{ | ||
} |
2 changes: 1 addition & 1 deletion
2
sample/Futurum.Microsoft.Extensions.DependencyInjection.Sample/ManualService.cs
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,5 +1,5 @@ | ||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Sample; | ||
|
||
public class ManualService : IService | ||
public class ManualService : IService1 | ||
{ | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...ons.DependencyInjection.Generator/RegistrationServiceTypeNotImplementedByClassAnalyzer.cs
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,41 @@ | ||
using System.Collections.Immutable; | ||
|
||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
|
||
namespace Futurum.Microsoft.Extensions.DependencyInjection.Generator; | ||
|
||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public class RegistrationServiceTypeNotImplementedByClassAnalyzer : DiagnosticAnalyzer | ||
{ | ||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } | ||
= ImmutableArray.Create(DiagnosticDescriptors.RegistrationServiceTypeNotImplementedByClass); | ||
|
||
public override void Initialize(AnalysisContext context) | ||
{ | ||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); | ||
context.EnableConcurrentExecution(); | ||
|
||
context.RegisterSymbolAction(Execute, SymbolKind.NamedType); | ||
} | ||
|
||
private static void Execute(SymbolAnalysisContext context) | ||
{ | ||
if (context.Symbol is not INamedTypeSymbol classSymbol) | ||
return; | ||
|
||
var attributes = Diagnostics.Registration.HasAttribute(classSymbol); | ||
if (!attributes.Any()) | ||
return; | ||
|
||
foreach (var attribute in attributes) | ||
{ | ||
var diagnostics = Diagnostics.Registration.ServiceTypeNotImplementedByClass.Check(classSymbol, attribute); | ||
|
||
foreach (var diagnostic in diagnostics) | ||
{ | ||
context.ReportDiagnostic(diagnostic); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.