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

Di/partials location formats/async writing #601

Conversation

MoazAlkharfan
Copy link

@MoazAlkharfan MoazAlkharfan commented Nov 1, 2023

  • Use FluidViewEngineOptions.PartialsLocationFormats to lookup partials files

    • protected virtual string ResolvePartialPath(string relativePartialPath)
      {
      return _partialToPartialPathCache.GetOrAdd(relativePartialPath, fileName =>
      {
      if (fileName.EndsWith(Constants.ViewExtension, StringComparison.OrdinalIgnoreCase))
      {
      return relativePartialPath;
      }
      foreach (var location in this._fluidViewEngineOptions.PartialsLocationFormats)
      {
      var partialPath = string.Format(location, fileName);
      var layoutPathInfo = this._fluidViewEngineOptions.PartialsFileProvider.GetFileInfo(partialPath);
      if (layoutPathInfo.Exists)
      {
      return partialPath;
      }
      }
      return fileName;
      });
      }
  • Use DI for FluidViewRenderer to allow for overriding

  • Configure for FluidMvcViewOptions to have consistent options values across the inheritance hierarchy

    • builder.Services.AddTransient<IConfigureOptions<FluidMvcViewOptions>, FluidViewEngineOptionsSetup<FluidMvcViewOptions>>();
      builder.Services.AddTransient<IConfigureOptions<FluidViewEngineOptions>, FluidViewEngineOptionsSetup<FluidViewEngineOptions>>();
      if (setupAction != null)
      {
      builder.Services.Configure<FluidMvcViewOptions>(setupAction);
      builder.Services.Configure(setupAction);
      }
services
       .AddControllersWithViews()
       .AddFluid(options => {
              /// ... Anything using FluidMvcViewOptions doesn't work with the configuration set here

              /// Options need to be repeated
       });

// Need this to set mvc options
services
       .Configure<FluidMvcViewOptions>(x =>
       {
              /// Before:
              /// Options need to be repeated here

              /// After:
              // Only this is needed to be configured
              x.RenderingViewAsync = (path, viewContext, context) =>
              {
                     return ValueTask.CompletedTask;
              };
       });
  • Add WriteToAsync because otherwise kestrel would throw and requires to override AllowSynchronousIO
builder.WebHost
        .UseKestrel(p =>
        {
            p.AllowSynchronousIO = true;
        });

@sebastienros
Copy link
Owner

@MoazAlkharfan I have integration the async part of your PR in #667, thanks for the contribution. I am keeping this one open since it also contains the configuration improvements but haven't looked at it closely enough to understand the problem so far (but I trust you about this).

@MoazAlkharfan
Copy link
Author

@sebastienros Created #672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants