JasperFx / wolverine

Supercharged .NET server side development!
https://wolverinefx.net
MIT License
1.21k stars 131 forks source link

"Application Assembly" detection should be similar to Marten #227

Open agross opened 1 year ago

agross commented 1 year ago

I was attempting to pregenerate the code for the handlers and found that it did not work while enforcing static loading only (Marten's code is fine and works with static type loading). Is the additional .cs file extension is an issue?

$ dotnet run --project src/Web/Web.csproj -- codegen write
Wrote generated code file to <path>/Internal/Generated/DocumentStorage/ArbeitsplatzInfoProvider376811002.cs
Wrote generated code file to <path>/Internal/Generated/DocumentStorage/KalenderblattInfoProvider1167327725.cs
Wrote generated code file to <path>/Internal/Generated/DocumentStorage/DeadLetterEventProvider834684974.cs
Wrote generated code file to <path>/Internal/Generated/EventStore/EventStorage.cs
Wrote generated code file to <path>/Internal/Generated/EventStore/KalenderblattInfoProjectionRuntimeSupport1451790746.cs
Wrote generated code file to <path>/Internal/Generated/EventStore/ArbeitsplatzInfoProjectionRuntimeSupport314459323.cs
Wrote generated code file to <path>/Internal/Generated/WolverineHandlers/ReservierbareArbeitsplätzeQueryHandler1144931484.cs.cs
Wrote generated code file to <path>/Internal/Generated/WolverineHandlers/ArbeitsplatzReservierenHandler1260337258.cs.cs
Wrote generated code file to <path>/Internal/Generated/WolverineHandlers/AlleArbeitsplätzeQueryHandler363102694.cs.cs

With options.CodeGeneration.TypeLoadMode = TypeLoadMode.Static this is logged as soon as a handler is invoked:

fail: Wolverine.Runtime.WolverineRuntime[0]
      Failed to create a message handler for Application.UseCases.Arbeitsplätze.Alle.AlleArbeitsplätzeQuery
      JasperFx.RuntimeCompiler.ExpectedTypeMissingException: Could not load expected pre-built types for code file AlleArbeitsplätzeQueryHandler363102694.cs (AlleArbeitsplätzeQuery handled by AlleArbeitsplätzeQueryHandler.Handle())
         at JasperFx.RuntimeCompiler.CodeFileExtensions.InitializeSynchronously(ICodeFile file, GenerationRules rules, ICodeFileCollection parent, IServiceProvider services)
         at Wolverine.Runtime.Handlers.HandlerGraph.HandlerFor(Type messageType)
         at Wolverine.Runtime.WolverineRuntime.Wolverine.Runtime.IExecutorFactory.BuildFor(Type messageType)
         at Wolverine.Runtime.WolverineRuntime.findInvoker(Type messageType)
jeremydmiller commented 1 year ago

Someone else reported the *.cs.cs problem. I honestly don't know if it's an issue or not TBH, but I also don't know how to reproduce that

agross commented 1 year ago

Found it! The duplicate file extension is unrelated to the types not loading. It's the Application Assembly.

Wolverine (0.9.12) handles the Application Assembly differently from Marten. Marten docs:

Just like ASP.Net MVC, Marten uses the IHostEnvironment.ApplicationName property to determine the main application assembly. If that value is missing, Marten falls back to the Assembly.GetEntryAssembly() value.

Wolverine 0.9.12 uses the assembly that runs UseWolverine() by default and no "detection magic" beyond that. Since in my solution UseWolverine() placed in a class library and not the main "web" assembly codegen writes the *.cs.cs files to, the generated code cannot be found.

jeremydmiller commented 1 year ago

That makes sense. That’s not a permutation I’d anticipated, but other folks have had completely different project structures. I think I’m the end it’s going to require a lot more docs about this, and maybe a unified codegen, resource config model between marten and wolverine. I started a GH discussion about that just yesterday. I’m on a family vacation starting today, so I’ll be out until mid next week. I’ll try to catch up fast when I’m backSent from my iPhoneOn Mar 9, 2023, at 1:37 AM, Alexander Groß @.***> wrote: Found it! The duplicate file extension is unrelated to the types not loading. It's the Application Assembly. Wolverine (0.9.12) handles the Application Assembly differently from Marten. Marten docs:

Just like ASP.Net MVC, Marten uses the IHostEnvironment.ApplicationName property to determine the main application assembly. If that value is missing, Marten falls back to the Assembly.GetEntryAssembly() value.

Wolverine 0.9.12 uses the assembly that runs UseWolverine() by default and no "detection magic" beyond that. Since in my solution UseWolverine() placed in a class library and not the main "web" assembly codegen writes the *.cs.cs files to, the generated code cannot be found.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

agross commented 1 year ago

I've seen both the GH discussion and that you are on vacation. Please enjoy your time off!

jeremydmiller commented 1 year ago

I'm not touching this other than documentation until after 1.0. I think it'd be worthy to consider any changes as part of https://github.com/JasperFx/marten/discussions/2522

jeremydmiller commented 1 month ago

This will be done as part of Wolverine 4.0 and Marten 8.0 later this year