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

do we have plan to use Blazor? #2966

Closed
infofromca opened this issue Jan 2, 2019 · 38 comments · Fixed by #10118
Closed

do we have plan to use Blazor? #2966

infofromca opened this issue Jan 2, 2019 · 38 comments · Fixed by #10118
Milestone

Comments

@infofromca
Copy link
Contributor

it seems that after we use Blazor in client (webAssembly), we do not need Liquid.

https://blazor.net/docs/get-started.html

@sebastienros
Copy link
Member

Right now the only release you can expect is Razor Components which is a server-side only technology. It's a different programming model than MVC. I don't think it replaces anything like Liquid.

However I am a truly believer that we should create some data oriented Razor Components like Data Sources in Webforms, that could reuse the data from Orchard. This would, like Razor Pages, allow for some nice decoupled website development in Orchard Core.

@Skrypt
Copy link
Contributor

Skrypt commented Jan 3, 2019

Nice post about the topic I found :
https://codedaze.io/introduction-to-server-side-blazor-aka-razor-components/

Fun sample I tried yesterday :
https://github.com/stevesandersonms/blazorelectronexperiment.sample

At this point I'd say it would be quite experimental. Though, fun project would be to try making Orchard Core work with Electron at the same time ! 😄

I'd say make it work with .NET Core 3.0 first.

@satakane
Copy link

satakane commented Oct 12, 2019

Has this been revisited now that ASP.NET Core 3 and Blazor serverside have been released?

@barthamark
Copy link
Contributor

I took a couple hours trying to add server-side Blazor to Orchard Core and I've succeeded -- I am now able to add Blazor components in any Orchard Core modules or themes. Unfortunately, I had to implement a workaround that we should discuss (see below).

First of all, what you need is to add a modular Startup file and add the server-side Blazor services and register the Blazor hub.

    public class Startup : StartupBase
    {
        public override void ConfigureServices(IServiceCollection services)
        {
            services.AddServerSideBlazor();
        }

        public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
        {
            routes.MapBlazorHub();
        }
    }

Secondly, inside the main Startup file of your web project add app.UseStaticFiles(); before app.UseOrchardCore();. Ultimately, it would be great to not do this or at least do it in the modular startup file but for now I didn't find a better solution.

Finally, make sure that the layout has the <base href="@Href("~/")" /> tag in the head and <script src="_framework/blazor.server.js"></script> in the foot scripts.

Unfortunately, this is not enough to make it work because you will get 404 to the _framework/blazor.server.js file in the browser.
It happens because when Blazor creates their file provider (see here and here in the ASP.NET Core source code) it will be overwritten by the OrchardCore static file configuration middleware (see: here).

It would be great to find a solution for this but until then the workaround is to re-register the Blazor embedded file provider in the main Startup file. Since the ConfigureStaticFilesOptions is internal you need to add it somewhere near the Startup file and delete the codes that references other internal settings (which is also not a good idea but it works). Something like this:

    public class BlazorConfigureStaticFilesOptions : IPostConfigureOptions<StaticFileOptions>
    {
        private readonly IWebHostEnvironment _environment;

        public BlazorConfigureStaticFilesOptions(IWebHostEnvironment environment)
        {
            _environment = environment;
        }

        public void PostConfigure(string name, StaticFileOptions options)
        {
            name = name ?? throw new ArgumentNullException(nameof(name));
            options = options ?? throw new ArgumentNullException(nameof(options));

            if (name != Options.DefaultName)
            {
                return;
            }

            // Basic initialization in case the options weren't initialized by any other component
            options.ContentTypeProvider = options.ContentTypeProvider ?? new FileExtensionContentTypeProvider();
            if (options.FileProvider == null && _environment.WebRootFileProvider == null)
            {
                throw new InvalidOperationException("Missing FileProvider.");
            }

            options.FileProvider = options.FileProvider ?? _environment.WebRootFileProvider;

            var provider = new ManifestEmbeddedFileProvider(typeof(IServerSideBlazorBuilder).Assembly);

            options.FileProvider = new CompositeFileProvider(provider, options.FileProvider);
        }
    }

And add the services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<StaticFileOptions>, BlazorConfigureStaticFilesOptions>()); line after the services.AddOrchardCms(); in the ConfigureServices method.

Please let me know your thoughts.

@jtkech
Copy link
Member

jtkech commented Nov 20, 2019

As i have time i will look at it, i need to learn Blazor first ;)

@sebastienros
Copy link
Member

What would be the goal?

  • Create webassembly applications that can request content from the server side? Though in this case it can just be two independent apps
  • Create a Blazor server side app that consumes content using APIs? Decoupled mode using Blazor at the front end in this case ... not sure it's adapted for websites (SEO, perf, ...)
  • Create multi-tenant or modular Blazor Apps?

@barthamark
Copy link
Contributor

@sebastienros any of them, I don't have an exact goal yet, I'm just exploring the possibilities. Basically, I want to know how deep I can go using Blazor components in Orchard Core. Even if it's a SPA using webassembly or it's a ContentPart editor shape using Blazor components on Admin. For now, I didn't try using Webassembly because it's not released yet but server-side Blazor would make sense.

@sebastienros sebastienros added this to the backlog milestone Nov 21, 2019
@miguelhasse
Copy link

miguelhasse commented Dec 12, 2019

How about having a Blazor version of Orchard Core's back-office.
It would also be nice to have a Blazor Component to render liquid pages.

@hishamco
Copy link
Member

I like the idea, but not all of us like Blazor, some prefer Razor, AngularJS .. etc

@sturlath
Copy link

What I'm looking at is to create a modular Blazor application witch is the reason I ended up looking at the Orchard Core Framework. Hopefully there will be some way to marry these two. Does this make sense or should I be looking at something else?

@Skrypt
Copy link
Contributor

Skrypt commented Dec 31, 2019

Should work but there's nothing so far planned about it I heard of. This is kind of a choice to make when building a module to use Vue.js or Angular or Blazor to make it work. We need to have some prototypes built first and see from there.

@sebastienros
Copy link
Member

There is a modular framework for Blazor called Octane that you could look at. https://www.oqtane.org/

@psijkof
Copy link
Contributor

psijkof commented Jan 15, 2020

I would like to build either a full blazor app, as an orchard core module and with other features and settings create a recipe to enable it as an app, multitenant mode.
Or use razor components in a regular mvc/razor pages app, modular, multitenant fashion....
Oqtane is blazor only, and not as flexible and open as orchard.
The apps/modules I'm enabling through my recipes and exposing them multitenant, should allow me to use everything there is in the asp.net core framework....

@jersiovic
Copy link
Contributor

We are developing our ERP with Orchard Core because we want its modularity and because it allows to have different frontend technology on each module. It ensures us a gradual migration of our modules to future front end technologies.
That's why I would like to see Blazor supported

@barthamark
Copy link
Contributor

barthamark commented Jan 16, 2020

I've created a sample Orchard Core CMS website (not decoupled) with two sample modules using
server-side Blazor. I've added code comments almost everywhere so you will see what steps are required to make it work when you implement your own. Since I am not sure what scenarios you'd like to support this sample is very simple so let me know what you have in your mind. https://github.com/barthamark/Orchard-Core-Blazor-Sample

Since Orchard Core websites can be modularized and server-side Blazor can be integrated (with workarounds, see my comment) we can add Blazor components to Orchard Core modules. This way we can enable or disable some features implemented using Blazor. As for not server-side Blazor the approach is completely different because you will build an SPA using Blazor and use Orchard Core as backend which is separated.

Please let me know if it helps.

@sebastienros
Copy link
Member

@barthamark do you want to demo it and talk about what it enables?

@barthamark
Copy link
Contributor

barthamark commented Jan 23, 2020

Yes, sure. Let's talk about this. I'll go to one of the next meetings and demo it. Thanks.

@agriffard
Copy link
Member

@barthamark Do you still want to make a demo during a meeting?

@barthamark
Copy link
Contributor

Yes, let's do it next week.

@barthamark
Copy link
Contributor

Unfortunately, I have to postpone this demo to next week because I got the cold and can't speak too much. Until next week, please let me know if you have a specific idea about where you'd find it useful to write modularized server-side Blazor components so I can create a couple more examples if needed.

@agriffard
Copy link
Member

I would also love to see a POC that uses Blazor WebAssembly.

See today's announcement:
https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-2-release-now-available/

It would be a Blazor Wasm app that calls some REST or GraphQL apis exposed by an Orchard Instance.
Kind of like what @OrchardSkills made with the Angular 8 Sample but with Blazor.

I created an issue about an Helper Library that would help to abstract the GraphQl calls to OC: #5434

@sebastienros
Copy link
Member

My new recommendation: Use Blazor Wasm if you want, in the admin or the frontend. But we shouldn't change Orchard in any way to add custom support for it, even less Blazor Server.

@hishamco
Copy link
Member

It could be a community driven project

@daveblack101
Copy link

@barthamark meeting's now in case you are available

@Piedone Piedone mentioned this issue Apr 5, 2020
@kevinvdm88
Copy link

Blazor Webassembly 3.2.0 is now fully released.
https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-now-available/

Do you guys have plans to add a testproject with it in Orchard ?

@hishamco
Copy link
Member

hishamco commented Jun 3, 2020

@kevinvdm88 we could add this into https://github.com/OrchardCoreContrib/OrchardCoreContrib.Themes

@ns8482e
Copy link
Contributor

ns8482e commented Jun 24, 2020

My new recommendation: Use Blazor Wasm if you want, in the admin or the frontend. But we shouldn't change Orchard in any way to add custom support for it, even less Blazor Server.

We could use Orchard Core as Back-end Server and Blazor Wasm as standalone Front-end web application ( not as orchard module) - It could be Good candidate for How-to guide.

@deanmarcussen
Copy link
Member

We could use Orchard Core as Back-end Server and Blazor Wasm as standalone Front-end web application ( not as orchard module) - It could be Good candidate for How-to guide.

Would be a Great How-to guide, and the right idea for seperation of concerns (IMHO) between back end Orchard Core and Blazor as a Front End

@Skrypt
Copy link
Contributor

Skrypt commented Sep 1, 2020

https://blog.stevensanderson.com/2019/11/01/exploring-lighter-alternatives-to-electron-for-hosting-a-blazor-desktop-app/

Just wanted to include a reference to this nice post on this topic. For example, if someone wanted to work on a Blazor admin dashboard app. This could be somehow quite experimental but also a good thing to try.

@OrchardSkills
Copy link

I have been experimenting with Blazor

Blazor Web Assembly with Orchard Core

Other Orchard Core Blazor Videos: https://www.youtube.com/c/OrchardSkills/videos

@xperiandri
Copy link
Contributor

So instead of #2966 (comment) I added

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
{
    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new ManifestEmbeddedFileProvider(typeof(IServerSideBlazorBuilder).Assembly),
    });

    routes.MapBlazorHub();
}

and it works perfect for all tenants

@sebastienros
Copy link
Member

@xperiandri can you explain what you can accomplish with that?

@xperiandri
Copy link
Contributor

I render Blazor component on some page like this <component type="typeof(Options)" render-mode="ServerPrerendered" />
In order to work it requires <script src="_framework/blazor.server.js"></script>
So my code above makes it work for all tenants

@ns8482e
Copy link
Contributor

ns8482e commented Aug 15, 2021

@sebastienros That's because StaticFileOptions are explicitly defined in OrchardCore instead of Resolved from DI by StaticMiddleware - resulted in IPostConfigureOptions<StaticOptions> not being called.

This can be easily fixed in OC, will create PR soon.

@psijkof
Copy link
Contributor

psijkof commented Mar 16, 2023

loading '_framework/blazor.server.js' works now by configuring the staticfileoptions with a ManifestEmbeddedFileProvider pointing to the blazor assembly.

How would I achieve for also resolving the '_content/etc.css' file from a RCL?

@xperiandri
Copy link
Contributor

@psijkof check obj folder structure and inspect embedded resources of the assembly

@websitewill
Copy link
Contributor

@psijkof @xperiandri did you figure this out and can share?
I think I am in the same boat - when I publish my site, I see all of the js+wasm files in the wwwroot folder, but I am not able to lad them. Oddly, _framework/blazor.web.js (which doesn't actually exist) is served, but the actual published output files such as the blazor.webassembly.js, dotnet.js, or the wasm files all result in 500 errors.

I suspect something I have to do with UseStaticFiles (where I call it, what I pass to it, something). But no idea what...

I am using Blazor8, BTW.

TIA!

@xperiandri
Copy link
Contributor

As far as I remember I had to adjust the path of js according to module name

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 a pull request may close this issue.