public void Initialize(GeneratorInitializationContext context) { const string attribute = @"// <auto-generated /> using Microsoft.Extensions.DependencyInjection; [System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false, Inherited = false)] internal class InjectAttribute : System.Attribute { internal InjectAttribute(ServiceLifetime serviceLifetime = ServiceLifetime.Transient) { } } [System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false, Inherited = false)] internal class InjectSingletonAttribute : System.Attribute { } [System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false, Inherited = false)] internal class InjectScopedAttribute : System.Attribute { } [System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false, Inherited = false)] internal class InjectTransientAttribute : System.Attribute { } "; context.RegisterForPostInitialization(context => context.AddSource("Inject.Generated.cs", SourceText.From(attribute, Encoding.UTF8))); context.RegisterForSyntaxNotifications(() => new ServicesReceiver()); }
public void Initialize(GeneratorInitializationContext context) { const string attribute = @"// <auto-generated /> [System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false, Inherited = false)] internal class AddServiceAttribute : System.Attribute { } "; context.RegisterForPostInitialization(context => context.AddSource("AddService.Generated.cs", SourceText.From(attribute, Encoding.UTF8))); context.RegisterForSyntaxNotifications(() => new ServicesReceiver()); }