همانطورکه با مطالعهی
سری آموزش Blazor تا به اینجا متوجه شدهاید، Blazor دو نوع Web Assembly و Server را دارد:
- در Blazor Web Assembly که UI با HTML / CSS زده میشود، کدهای C# .NET ای با کمک Web Assembly و داخل خود مرورگر اجرا میشوند. با کمک Blazor Web Assembly میتوان محصولات PWA و SPA ایجاد نمود.
- در Blazor Server که UI با HTML / CSS زده میشود، کدها در سرور اجرا و به وسیلهی Web Sockets، تعاملات UI ای از Browser به سرور ارسال و تغییرات UI ای از سرور به Browser ارسال میشوند. با کمک Blazor Server میتوان محصولات SPA ایجاد نمود.
ولی دو نوع Blazor دیگر نیز وجود دارند:
- Blazor Native Mobile Apps که در این روش از کامپوننتهای Native موبایل استفاده میشود؛ نه عناصر HTML مانند h1 و div. با کمک Blazor Native Mobile Apps میتوان برنامههای Native موبایل برای Android / iOS و برنامههای Desktop برای Windows ایجاد نمود.
- Blazor Hybrid که در این روش UI با HTML / CSS بوده، ولی اجرای کدهای C# .NET داخل خود سیستم عامل و به صورت Native است. با کمک Blazor Hybrid میتوان برنامههای موبایل برای Android / iOS و برنامههای Desktop برای Windows ایجاد نمود.
از Blazor Hybrid زمانی استفاده میکنیم که بخواهیم برنامههای موبایل را برای Android / iOS و برنامههای Desktop را برای ویندوز، با کمک HTML / CSS توسعه دهیم.
حال سوال اینجاست که این چه تفاوتی با ارائه یک PWA با Blazor Web Assembly دارد؟
تفاوت در نحوهی اجرا شدن کدهای C# .NET است. در Blazor Web Assembly، کدها درون Sandbox خود Browser اجرا میشوند و طبیعتا محدود به امکانات خود Browser هستند؛ برای مثال امکان خواندن Contactهای گوشی وجود ندارد.
همچنین هنوز نسخهی AOT برای Blazor Web Assembly هنوز آماده نشده است و در Blazor Hybrid چون اجرای C# .NET به صورت Native است، Performance خیلی خوبی دارد.
به علاوه، با اشتراک گذاری اصل کد بین Blazor Web Assembly و Blazor Hybrid میتوان هم یک PWA / SPA داشت و هم آن را در Storeها پابلیش نمود که این به معنای جذب بیشتر مشتری است. این نسخهی پابلیش شده روی Store، چون حاوی فایلهای لازم، اعم از CSS و DLLها و... است، به محض دانلود، قابلیت استفاده دارد و لازم ندارد مجددا چیزی را از سرور دانلود کند. به واقع با این روش میتوان حتی Offline mobile & desktop apps ایجاد نمود.
مستندات مایکروسافت برای ایجاد یک Blazor Hybrid app در
اینجا قرار دارند. به علاوه یک
Sample project را نیز در GitHub ارائه کردهام که در قسمت Releases آن، یک apk برای Android deviceهای 64 بیتی نیز قرار داده شدهاست که میتوانید آنرا تست کنید. باقی کدهایی که در پروژه نوشته میشوند، دقیقا مشابه همین مطالب
سری آموزش Blazor است که احتمالا تا این لحظه آنها را مطالعه نمودهاید.