Skip to content

Commit

Permalink
Updating generators to fix the namespace conflict with customer code (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
surgupta-msft authored Jul 10, 2024
1 parent 228018b commit 53d764e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ namespace {{FunctionsUtil.GetNamespaceForGeneratedCode(context)}}
{
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class DirectFunctionExecutor : IFunctionExecutor
internal class DirectFunctionExecutor : global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor
{
private readonly IFunctionActivator _functionActivator;{{(defaultExecutorNeeded ? $"{Environment.NewLine} private Lazy<IFunctionExecutor> _defaultExecutor;" : string.Empty)}}
private readonly global::Microsoft.Azure.Functions.Worker.IFunctionActivator _functionActivator;{{(defaultExecutorNeeded ? $"{Environment.NewLine} private Lazy<global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor> _defaultExecutor;" : string.Empty)}}
{{GetTypesDictionary(functions)}}
public DirectFunctionExecutor(IFunctionActivator functionActivator)
public DirectFunctionExecutor(global::Microsoft.Azure.Functions.Worker.IFunctionActivator functionActivator)
{
_functionActivator = functionActivator ?? throw new ArgumentNullException(nameof(functionActivator));
_functionActivator = functionActivator ?? throw new global::System.ArgumentNullException(nameof(functionActivator));
}

/// <inheritdoc/>
public async ValueTask ExecuteAsync(FunctionContext context)
public async global::System.Threading.Tasks.ValueTask ExecuteAsync(global::Microsoft.Azure.Functions.Worker.FunctionContext context)
{
{{GetMethodBody(functions, defaultExecutorNeeded)}}
}{{(defaultExecutorNeeded ? $"{Environment.NewLine}{EmitCreateDefaultExecutorMethod(context)}" : string.Empty)}}
Expand All @@ -62,7 +62,7 @@ public static IHostBuilder ConfigureGeneratedFunctionExecutor(this IHostBuilder
{
return builder.ConfigureServices(s =>
{
s.AddSingleton<IFunctionExecutor, DirectFunctionExecutor>();
s.AddSingleton<global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor, DirectFunctionExecutor>();
});
}
}{{GetAutoConfigureStartupClass(includeAutoRegistrationCode)}}
Expand All @@ -79,12 +79,12 @@ private static string EmitCreateDefaultExecutorMethod(GeneratorExecutionContext

return $$"""

private IFunctionExecutor CreateDefaultExecutorInstance(FunctionContext context)
private global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor CreateDefaultExecutorInstance(global::Microsoft.Azure.Functions.Worker.FunctionContext context)
{
var defaultExecutorFullName = "Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor, {{assemblyIdentity}}";
var defaultExecutorType = Type.GetType(defaultExecutorFullName);
var defaultExecutorType = global::System.Type.GetType(defaultExecutorFullName);

return ActivatorUtilities.CreateInstance(context.InstanceServices, defaultExecutorType) as IFunctionExecutor;
return ActivatorUtilities.CreateInstance(context.InstanceServices, defaultExecutorType) as global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor;
}
""";
}
Expand Down Expand Up @@ -121,7 +121,7 @@ private static string GetAutoConfigureStartupClass(bool includeAutoRegistrationC
/// Auto startup class to register the custom <see cref="IFunctionExecutor"/> implementation generated for the current worker.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
public class FunctionExecutorAutoStartup : IAutoConfigureStartup
public class FunctionExecutorAutoStartup : global::Microsoft.Azure.Functions.Worker.IAutoConfigureStartup
{
/// <summary>
/// Configures the <see cref="IHostBuilder"/> to use the custom <see cref="IFunctionExecutor"/> implementation generated for the current worker.
Expand All @@ -144,10 +144,10 @@ private static string GetMethodBody(IEnumerable<ExecutableFunction> functions, b
var sb = new StringBuilder();
sb.Append(
$$"""
var inputBindingFeature = context.Features.Get<IFunctionInputBindingFeature>();
var inputBindingFeature = context.Features.Get<global::Microsoft.Azure.Functions.Worker.Context.Features.IFunctionInputBindingFeature>();
var inputBindingResult = await inputBindingFeature.BindFunctionInputAsync(context);
var inputArguments = inputBindingResult.Values;
{{(anyDefaultExecutor ? $" _defaultExecutor = new Lazy<IFunctionExecutor>(() => CreateDefaultExecutorInstance(context));{Environment.NewLine}" : string.Empty)}}
{{(anyDefaultExecutor ? $" _defaultExecutor = new Lazy<global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor>(() => CreateDefaultExecutorInstance(context));{Environment.NewLine}" : string.Empty)}}
""");

bool first = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static string GetAutoConfigureStartupClass(bool includeAutoRegistrationC
/// Auto startup class to register the custom <see cref="IFunctionMetadataProvider"/> implementation generated for the current worker.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
public class FunctionMetadataProviderAutoStartup : IAutoConfigureStartup
public class FunctionMetadataProviderAutoStartup : global::Microsoft.Azure.Functions.Worker.IAutoConfigureStartup
{
/// <summary>
/// Configures the <see cref="IHostBuilder"/> to use the custom <see cref="IFunctionMetadataProvider"/> implementation generated for the current worker.
Expand Down
1 change: 1 addition & 0 deletions sdk/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@

- ExtensionStartupRunnerGenerator generating code which conflicts with customer code (namespace) (#2542)
- Enhanced function metadata generation to include `$return` binding for HTTP trigger functions. (#1619)
- Updating generators to fix the namespace conflict with customer code (#2582)
28 changes: 14 additions & 14 deletions test/Sdk.Generator.Tests/FunctionExecutor/DependentAssemblyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ namespace TestProject
{
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class DirectFunctionExecutor : IFunctionExecutor
internal class DirectFunctionExecutor : global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor
{
private readonly IFunctionActivator _functionActivator;
private Lazy<IFunctionExecutor> _defaultExecutor;
private readonly global::Microsoft.Azure.Functions.Worker.IFunctionActivator _functionActivator;
private Lazy<global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor> _defaultExecutor;
private readonly Dictionary<string, Type> types = new Dictionary<string, Type>()
{
{ "MyCompany.MyHttpTriggers", Type.GetType("MyCompany.MyHttpTriggers, TestProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null") },
Expand All @@ -83,19 +83,19 @@ internal class DirectFunctionExecutor : IFunctionExecutor
{ "MyCompany.MyProduct.MyApp.Foo.Bar", Type.GetType("MyCompany.MyProduct.MyApp.Foo.Bar, DependentAssemblyWithFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") }
};

public DirectFunctionExecutor(IFunctionActivator functionActivator)
public DirectFunctionExecutor(global::Microsoft.Azure.Functions.Worker.IFunctionActivator functionActivator)
{
_functionActivator = functionActivator ?? throw new ArgumentNullException(nameof(functionActivator));
_functionActivator = functionActivator ?? throw new global::System.ArgumentNullException(nameof(functionActivator));
}

/// <inheritdoc/>
public async ValueTask ExecuteAsync(FunctionContext context)
public async global::System.Threading.Tasks.ValueTask ExecuteAsync(global::Microsoft.Azure.Functions.Worker.FunctionContext context)
{
var inputBindingFeature = context.Features.Get<IFunctionInputBindingFeature>();
var inputBindingFeature = context.Features.Get<global::Microsoft.Azure.Functions.Worker.Context.Features.IFunctionInputBindingFeature>();
var inputBindingResult = await inputBindingFeature.BindFunctionInputAsync(context);
var inputArguments = inputBindingResult.Values;
_defaultExecutor = new Lazy<IFunctionExecutor>(() => CreateDefaultExecutorInstance(context));
_defaultExecutor = new Lazy<global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor>(() => CreateDefaultExecutorInstance(context));

if (string.Equals(context.FunctionDefinition.EntryPoint, "MyCompany.MyHttpTriggers.Foo", StringComparison.Ordinal))
{
var instanceType = types["MyCompany.MyHttpTriggers"];
Expand Down Expand Up @@ -130,12 +130,12 @@ public async ValueTask ExecuteAsync(FunctionContext context)
}
}

private IFunctionExecutor CreateDefaultExecutorInstance(FunctionContext context)
private global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor CreateDefaultExecutorInstance(global::Microsoft.Azure.Functions.Worker.FunctionContext context)
{
var defaultExecutorFullName = "Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor, Microsoft.Azure.Functions.Worker.Core, Version=1.18.0.0, Culture=neutral, PublicKeyToken=551316b6919f366c";
var defaultExecutorType = Type.GetType(defaultExecutorFullName);
return ActivatorUtilities.CreateInstance(context.InstanceServices, defaultExecutorType) as IFunctionExecutor;
var defaultExecutorType = global::System.Type.GetType(defaultExecutorFullName);

return ActivatorUtilities.CreateInstance(context.InstanceServices, defaultExecutorType) as global::Microsoft.Azure.Functions.Worker.Invocation.IFunctionExecutor;
}
}
{{GetExpectedExtensionMethodCode()}}
Expand Down
Loading

0 comments on commit 53d764e

Please sign in to comment.