Giter Club home page Giter Club logo

maui-blazor-web-template's People

Contributors

one1lion avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

maui-blazor-web-template's Issues

Feature Request: Add CORS support?

I added Microsoft.Extensions.Http library to my Shared library in the ServiceExtensions.cs file. I also have a separate project for my ASP.Net Core Web API backend. When running the code with WASM, I get a CORS issue. Any ideas on what to add to account for that? Or is the CORS setting on the API side?

BTW, the http calls to the API work great with the Maui and ServerOnly platforms.

Feature Request: Add local caching using SQLite

It would be awesome to add SQLite support for Maui and WASM for when a connection to the API server is down. Then using a sync button or method to sync the data to/from the API server.

I plan to put my code into the Shared class using some singleton repository so it can be used by all the platforms except ServerOnly. I am not quite sure how to check for the ServerOnly is being used in order to not use the cache.

Feature Request: Add application Globals.cs

Here is my code for a Global cache service. Create a new file called Globals.cs in the MyApp.Shared.Services folder.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyApp.Shared.Services
{
        public string AppType;
        public string Url1;
        public string Url2;

        public string Get(string Key)
        {
            if (Key == "AppType")
            {
                if (string.IsNullOrWhiteSpace(AppType))
                {
                    // TODO: Get the value from a settings file
                    AppType = "MAUI";
                }
                return AppType;
            }
            else if (Key == "Url1")
            {
                if (string.IsNullOrWhiteSpace(Url1))
                {
                    // TODO: Get the value from a settings file
                    Url1 = @"https://localhost:7055/api/url1;
                }
                return Url1;
            }
            else if (Key == "Url2")
            {
                if (string.IsNullOrWhiteSpace(Url2))
                {
                    // TODO: Get the value from a settings file
                    Url2 = @"https://localhost:7055/api/url2";
                }
                return Url2;
            }

            return "";
        }
    }
}

Then add this to the MyApp.Shared.Extensions.ServiceExtensions file:

        public static void AddSharedServices(this IServiceCollection services)
        {
            services.AddHttpClient();
            services.AddSingleton<MyApp.Shared.Services.Globals>();
        }

Then create a "Repos" folder under MyApp.Shared to hold all calls to the API:

using MyApp.Shared.Models.HCM.JD.Onet;
using System.Net.Http.Headers;
using System.Configuration;
using Microsoft.AspNetCore.Components;
using MyApp.Shared.Services;

namespace MyApp.Shared.Repos.HCM.JD.Onet
{
    public class RepoUrl1
    {
        private readonly HttpClient client = new HttpClient();
        private readonly Globals _globals;
        public OnetRepo(Globals globals)
        {
            _globals = globals;
        }

        public async Task<IEnumerable<MyModel>?> GetMyModel()
        {

            // Get data from the API 
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("User-Agent", "Your application name here");
            var stringTask = client.GetStringAsync(Path.Combine(_globals.Get("Url1"), "MyModelNameHere"));
            var json = await stringTask;
            var records = JsonConvert.DeserializeObject<IEnumerable<MyModel>>(json);

  return records;
        }
    }l
}

And lastly, pass a reference from the UI to the Repo for the injected Globals in the UI page (i.e. Index.razor.cs):

namespace MyApp.Ui
{
    public partial class Index
    {
        [Inject] public Globals globals { get; set; }

        protected override async Task OnInitializedAsync()
        {
            Repo1 repo1= new Repo1 (globals);
            items = await repo1.GetMyModel();
        }
    }
}

Please feel free to add this to the GitHub project if it adds any value. Note the globals.cs file could use a dictionary instead of the way I did it.

Also note, this solution hard codes the global values. I am still trying to figure out how to call them from a config/app settings file which works with all project types. #6

Best approach to use 3rd party Blazor controls

Can you please incorporate the best way to use 3rd party Blazor controls like Syncfusion.Blazor.Charts in a centralized fashion?

The setup requires we add
builder.Services.AddSyncfusionBlazor();

to the Program.cs file. I would prefer to only put Syncfusion in the Shared.Ui project.

Thanks

Feature Request: Centralized Settings File

I ran into an issue I am trying to fix. If I get it working, will send you the code.

How to create an application settings file on the Shared project and works for all the projects? In particular, I need to put the URL to the web API into a config file. Just putting the idea here in case anyone else wishes to assist.

I have all my API calls located in the Shared project and my user interfaces in the Ui project. I plan to include some caching mechanism in the near future which will also be located in the Shared project.

Template installation clarification

I have been struggling on getting this all wired up by myself and stumbled into your template, awesome. II am not clear on how to install the template into my Visual Studio. Do I need to download the template project from GitHub? Or is there an MSI to install the template. The instruction on the readme page didn't work.

C:\Users\Brian\source\repos\FE>dotnet new -i .
The following template packages will be installed:
   C:\Users\Brian\source\repos\FE

No templates were found in the package C:\Users\Brian\source\repos\FE.

C:\Users\Brian\source\repos\FE>dotnet new maui-blazor-web
No templates found matching: 'maui-blazor-web'.

To list installed templates, run:
   dotnet new --list
To search for the templates on NuGet.org, run:
   dotnet new maui-blazor-web --search

C:\Users\Brian\source\repos\FE>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.