Daddoon / BlazorMobile

Create full C# driven hybrid-apps for iOS, Android, UWP & Desktop with Blazor!
MIT License
413 stars 55 forks source link

Can we use BlazorDevice.RuntimePlatform everywhere in the application lifetime? #223

Closed arivera12 closed 4 years ago

arivera12 commented 4 years ago

I need to specify some api calls, some of them over blazor web, others them over blazormobile,

It's safe to use BlazorDevice.RuntimePlatform?

Daddoon commented 4 years ago

As i have just written in your other post, you may slice your app in a Razor Class Library, and only reference BlazorMobile on a specific boot project, and not in the Web only app. By this avoiding to reference library you don't need on Web only projects.

This is of course not mandatory, only if you want to have a more lightweight app in the end if you have a lot of different implementation on Web and Native.

This said, maybe you are not looking for this, or just wanting to validate your concept at the moment ! So you may do this never, or in a later stage.

To answer your question, BlazorDevice.RuntimePlatform will return Unknown at a very early stage, and Browser if it was unable to connect at all to a native device. So you can assume that if you have one of theses 2 values, you are in a regular browser app.

Of course, if you implement what i have said at the beginning of this message, you would no need to think about it, because you would know that BlazorMobile would not even be present on your Web only app version, and so it's API. You would then only rely on a magical value you would set by yourself in your own class, set in the only not shared part of the app, that would be the base project. But at least of course the magical variable would have to be referenced in your RCL Blazor project to you use it in your code logic everywhere. You would just need to set it at boot, like Mobile equal true when starting in your Program.cs for example in the BlazorMobile Blazor project starting file, and the same with false when in the Web only Program.cs starting file.

With the same logic, only implement specific C# services implementations and registrations in the specifics base project too. This way any particularity is hidden in your Blazor RCL project, it will be at least present in the non common parts only.

arivera12 commented 4 years ago

To answer your question, BlazorDevice.RuntimePlatform will return Unknown at a very early stage, and Browser if it was unable to connect at all to a native device. So you can assume that if you have one of theses 2 values, you are in a regular browser app.

I already saw this.

With the same logic, only implement specific C# services implementations and registrations in the specifics base project too.

This is the approach I was thinking.

I would setup a base class which holds all this stuff internally as well separate most of this services in separate projects.