locked
blazor server | class library limits RRS feed

  • Question

  • User2110873642 posted

    when i make websites in blazor, there are a lot of things that i want to re-use between projects using class libraries.

    the problem is that all i want to externalise is all in _host.cshtml (intercepting httpcontext, and referencing .js files), and startup.cs (mostly DI)

    Friday, August 14, 2020 5:02 PM

All replies

  • User-821857111 posted

    Perhaps if you give one specific example of an issue you are facing where Blazor prevents you from using a class library, someone might be able to point you in the right direction. Personally, I have no problems using class libraries in Blazor applications.

    Friday, August 14, 2020 5:25 PM
  • User-474980206 posted

    you seem to not understand blazor server. Its not a website, its a connected stateful service listening on a signal/r pipeline. there are are no http requests or responses. it hosts the blazor dll and signal/r pipeline, but does not generally serve any assets (.js, img, etc). the blazor app host page should reference js files and assets.  If the blazor app served an image, it typically would be a dataurl string.

    you may be confused because an asp.net core application can host both a website for the blazor app host page and assets and the blazer server which hosts the blazor app. But they do not need to be the same server.  

    libraries you share with blazor apps should be logic, and not have any web server pipeline code. 

    Friday, August 14, 2020 7:28 PM
  • User2110873642 posted

    well for example i want to create a analytics log plugin for any website that uses blazor. it keeps track of pages, parameters and ip adresses.

    but you can only obtain a IP adress on the first requests, so i would have to obtain it on the _host.cshtml, pass it as param, in the app initialiser <app/> register a scoped service to mange state for the ip adress. (because it only exists in the first request).

    making it super hard to offhand that to a class library. i dont want the main app to take care of it, because it is hard and spagettish to keep. and a real pain to maintain updates between projects. because i want to re-use it.

    another example is a file upload control.

    for it to work, you need to register a .js file on _host.cshtml, because razor pages do not register .js files on render.

    Friday, August 14, 2020 9:20 PM
  • User2110873642 posted

    well, the problem is that i dont agree with the specification and design guidelines.. :c

    Friday, August 14, 2020 9:25 PM
  • User2110873642 posted

    you seem to not understand blazor server. Its not a website, its a connected stateful service listening on a signal/r pipeline. there are are no http requests or responses. it hosts the blazor dll and signal/r pipeline, but does not generally serve any assets (.js, img, etc). the blazor app host page should reference js files and assets.  If the blazor app served an image, it typically would be a dataurl string.

    i know all of this, everything.

    you may be confused because an asp.net core application can host both a website for the blazor app host page and assets and the blazer server which hosts the blazor app. But they do not need to be the same server.  

    i know this too, but i do not want it to work this way. i want to do everything in blazor so that it stays flexible.

    libraries you share with blazor apps should be logic, and not have any web server pipeline code. 

    what about all these nuget packages available? they are mostly pipline code. these arent class libraries?

    Friday, August 14, 2020 9:30 PM
  • User-474980206 posted

    you are writing a client app. to get the ipaddress, its a simple javascript interop

    fetch('https://www.cloudflare.com/cdn-cgi/trace')
      .then(data => data.text())
      .then(data => console.log(data);

    wrapping this with a simple blazor component is easy and storing the ipaddress. as there are no requests, you probably want log a component render, or navigation.

    say at the root capture ipaddress

    <RegisterLog appid="my app" .../>

    then in a component add the log

      <LogEvent tag="my component" .. />

    a file upload control would probably use javascript interop to inject the required html and javascript/script or just require a script ref after the blazor ref. here is an example:

       https://github.com/DataJuggler/BlazorFileUpload

    I expect that once WASM Blazor has fast loading and better project tooling, the server version will become a little used tool (maybe even dropped). After all you can not make a PWA with blazor server and a complex UI will always be sluggish compared to WASM.

    Friday, August 14, 2020 10:33 PM
  • User-821857111 posted

    Maybe Blazor is not the right framework for your needs. 

    Saturday, August 15, 2020 6:00 AM
  • User2110873642 posted

    i know. i basically want it to not be SPA. and definetely not PWA.

    its just that i need rich ui on some most of the pages, and because it is data bound ui, i cant really go around blazor.

    its just that blazor comes closest to what i need.

    ----

    someone just mentioned that blazor server might be dropped when WASM gets better. is this a big concern for me? (ill move this question to a new thread, since its not really allowed to get into it deeper here)

    Saturday, August 15, 2020 8:52 AM