- 
                Notifications
    
You must be signed in to change notification settings  - Fork 200
 
Auto register auto generated IHostBuilder extension methods #1794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…utes. Updated tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! also like the naming choices as is.
| 
           Do we need to have both  Just running the permutations: 
 I think we would be best off keeping it simple and confined to the MSBuild option.  | 
    
…tor msbuild prop to "True". Removing version suffix from package versions.
…hub.com/Azure/azure-functions-dotnet-worker into shkr/1611_auto_register_src_gen_methods
          
 Thanks @mattchenderson I pushed a new iteration which sets the default value of  Sample usage of the 3 msuild properties. <FunctionsEnableWorkerIndexing>True</FunctionsEnableWorkerIndexing>
<FunctionsAutoRegisterGeneratedMetadataProvider>True</FunctionsAutoRegisterGeneratedMetadataProvider>
<FunctionsEnableExecutorSourceGen>True</FunctionsEnableExecutorSourceGen> | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attribute route for discovering and invoking these extensions is fine. You could also create a new interface which has a Configure(IHostBuilder builder) on it, which you will discover, activate, and invoke. Both approaches are fine, so it is up to your preference.
        
          
                src/DotNetWorker.Core/Hosting/CoreWorkerHostBuilderExtensions.cs
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/DotNetWorker.Core/Hosting/CoreWorkerHostBuilderExtensions.cs
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
          
 I considered this route, but found a few issues. Currently we generate an extension method  Another option is to not emit the static extension method and static class. Simply create a class which implements the said interface with  Third option is to have an additional class (which implements the said interface) along with existing extension method classes. But I thought that seems more code we are emitting. So I decided to not go that route. But I am happy to pivot if there is a better way to handle this. Thoughts?  | 
    
          
 This is what I was thinking if you did decide to go that route. Yes, it is more code to emit, but that doesn't really cost anything besides authoring the generator itself. I am fine with either route, interface or attributes. Another idea for attributes is to remove the method attribute and instead look for method by convention: static, public, named "Configure", accepts  My main concern is that it is two separate attributes needed. It just feels a bit unwieldy/confusing to me. But that is also not a blocker, I can live with it if you don't want to change it.  | 
    
          
 Pushed a new iteration which does this (interface) instead of the attribute based solution.  | 
    
Fixes #1161
Auto register the
IHostBuilderextension methods emitted by our source generators for metadata provider and function executor.Currently we have 2 methods we want to explicitly register in main like below.
In this PR we are introducing a new interface
IAutoConfigureStartupas below.Any class which wants to do auto configuration during startup should implement this interface. Those types will be discovered when the app starts and the Configure method will be invoked.
Updated both the source generators to emit an implementation of the above interface. The
Configuremethod is simply calling the existing extension method as shown below.The behavior is disabled by default and one can enable them by setting the below MSBuild property.
For function executor registration, the default behavior is to auto register as long as the code is generated. But if user wishes to disable it, they can do it by doing the following.
Sample csproj file content where auto registration of generated function metadata provider and generated executor.
Pull request checklist
release_notes.md