Closed pfeigl closed 5 years ago
I actually managed to do it with the following steps:
Register required services (exluding all the ViewEngine implementations)
services.AddScoped<IOptions<FluidViewEngineOptions>, DatabaseFluidViewEngineOptions>();
services.AddScoped<IFluidRendering, FluidRendering>();
Implement IOptions
Just depend on IFluidRendering wherever needed and call the RenderAsync :)
Some remarks which i stumpled upon, which might make nice improvements to the library:
IOptions is always resolved in a Singleton manner when registered via IConfigureOptions (see https://github.com/aspnet/Options/blob/dev/src/Microsoft.Extensions.Options/OptionsServiceCollectionExtensions.cs#L30). This effectively prevents injecting non singleton dependencies into the IConfigureOptions implementation. => i.e. it's not possible to depend on the DbContext
The LayoutTag is hardcoded on Path.* calls instead of using the FileProvider => This fails gracefully because non of the calls actually fail when the files don't really exist, but in my opinion the FileSystem should not be accessed directly here
FluidViewEngine depends on FluidRendering, but than again FluidRendering uses static properties of the FluidViewEngine. While it works as everything is in the same assembly, effectively this is a circular dependency.
FluidViewEngine.ViewExtension is readonly, which prevents customizing this
Possibly some of those points were intentionally chosen like that, they gave me some headaches while implementing a database based FileProvider :)
Might as well file issues for each of your comments.
@pfeigl is the issue still happen?
I don't know to be honest, we meanwhile changed to https://github.com/lunet-io/scriban
So this need to be closed
@pfeigl NOOOOOOOOOO!!! Fluid is so much better ;) Just kidding, everything @xoofx does is awesome!
We are in a pure API stack and use fluid to generate E-Mail contents. We would like to use the extensibility features of the templates (namely layout, renderbody, section and rendersection) to compose our e-mails, so my question is, whether this can be easily accomplished.
I tried simply referencing Fluid.MvcViewEngine and calling the following:
And while the TryParse works (meaning it is recognizing the template tag), that RenderAsync call fails with
I probably miss quite some setup which is normally done in the "AddFluid" call in the startup.