Skip to content
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

Removing an assertion that doesn't really help that was breaking code… #1042

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Testing/CoreTests/Codegen/TestingTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ namespace CoreTests.Codegen;
public interface IWidget{}

public class AWidget : IWidget{}
public class BWidget : IWidget{}

public class ServiceUsingWidget : IWidget
{
public ServiceUsingWidget(IColor color)
{
Color = color;
}

public IColor Color { get; set; }
}

public interface ISingletonLambda{}
public class SingletonLambda : ISingletonLambda{}
Expand Down
63 changes: 63 additions & 0 deletions src/Testing/CoreTests/Codegen/enumerable_dependencies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Diagnostics;
using JasperFx.CodeGeneration;
using JasperFx.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Wolverine.Tracking;
using Xunit;

namespace CoreTests.Codegen;

public class enumerable_dependencies
{
[Fact]
public async Task can_use_mixed_scoping_of_array_elements()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.Services.AddSingleton<IColor, Red>();
opts.Services.AddSingleton<IWidget, AWidget>();
opts.Services.AddSingleton<IWidget, BWidget>();
opts.Services.AddScoped<IWidget, ServiceUsingWidget>();

opts.CodeGeneration.GeneratedCodeOutputPath = AppContext.BaseDirectory
.ParentDirectory().ParentDirectory().ParentDirectory().AppendPath("Internal", "Generated");
opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto;


}).StartAsync();

await host.InvokeMessageAndWaitAsync(new WidgetUsingMessage());
await host.InvokeMessageAndWaitAsync(new WidgetUsingMessage2());
}
}

public record WidgetUsingMessage;
public record WidgetUsingMessage2;

public static class WidgetUsingMessageHandler
{
public static void Handle(WidgetUsingMessage message, IEnumerable<IWidget> widgets)
{
// Don't really need to do anything here
Debug.WriteLine("Got here");
}
}

public class WidgetUsingMessage2Handler
{
private readonly IWidget[] _widgets;

public WidgetUsingMessage2Handler(IEnumerable<IWidget> widgets)
{
_widgets = widgets.ToArray();
}


public void Handle(WidgetUsingMessage2 message)
{
_widgets.Any().ShouldBeTrue();
Debug.WriteLine("Got here");
}
}
5 changes: 5 additions & 0 deletions src/Wolverine/Codegen/ArrayPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public ArrayFamily(Type serviceType) : base(serviceType, [new ServiceDescriptor(
public override ServicePlan? BuildDefaultPlan(ServiceContainer graph, List<ServiceDescriptor> trail)
{
var plans = graph.FindAll(ElementType, trail);

#if NET8_0_OR_GREATER
if (plans.Any(x => x.Descriptor.IsKeyedService)) return new ServiceLocationPlan(Default);
#endif

if (plans.All(x => x.Lifetime == ServiceLifetime.Singleton))
{
return new SingletonPlan(Default);
Expand Down
11 changes: 1 addition & 10 deletions src/Wolverine/Codegen/ServiceLocationPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ internal class ServiceLocationPlan : ServicePlan
{
public ServiceLocationPlan(ServiceDescriptor descriptor) : base(descriptor)
{
#if NET8_0_OR_GREATER
if (descriptor.IsKeyedService)
{
ArgumentNullException.ThrowIfNull(descriptor.KeyedImplementationFactory);
}
else
{
ArgumentNullException.ThrowIfNull(descriptor.ImplementationFactory);
}
#endif

}

protected override bool requiresServiceProvider(IMethodVariables method)
Expand Down
Loading