Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
6002CEM_LiYang/MauiProgram.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
58 lines (51 sloc)
1.79 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using CommunityToolkit.Maui; | |
using Microsoft.Extensions.Logging; | |
using ShoppingList.Services; | |
using ShoppingList.ViewModel; | |
using ShoppingList.Views; | |
namespace ShoppingList; | |
public static class MauiProgram | |
{ | |
public static MauiApp CreateMauiApp() | |
{ | |
return MauiApp | |
.CreateBuilder() | |
.UseMauiApp<App>() | |
.ConfigureFonts(fonts => | |
{ | |
fonts.AddFont("Jost-Regular.ttf", "JostRegular"); | |
fonts.AddFont("Jost-SemiBold.ttf", "JostSemiBold"); | |
}) | |
.UseMauiCommunityToolkit() | |
.RegisterServices() | |
.RegisterViewModels() | |
.RegisterViews() | |
.Build(); | |
} | |
private static MauiAppBuilder RegisterServices(this MauiAppBuilder builder) | |
{ | |
builder.Services.AddSingleton<IDatabaseProvider, DatabaseProvider>(); | |
builder.Services.AddSingleton<IStoreService, StoreService>(); | |
builder.Services.AddSingleton<IItemService, ItemService>(); | |
builder.Services.AddSingleton<IClipboardService, ClipboardService>(); | |
builder.Services.AddLogging(); | |
#if DEBUG | |
builder.Logging.AddDebug(); | |
#endif | |
return builder; | |
} | |
private static MauiAppBuilder RegisterViewModels(this MauiAppBuilder builder) | |
{ | |
builder.Services.AddSingleton<MainViewModel>(); | |
builder.Services.AddSingleton<StoresViewModel>(); | |
builder.Services.AddTransient<DetailViewModel>(); | |
return builder; | |
} | |
private static MauiAppBuilder RegisterViews(this MauiAppBuilder builder) | |
{ | |
builder.Services.AddSingleton<MainPage>(); | |
builder.Services.AddSingleton<StoresPage>(); | |
builder.Services.AddTransient<DetailPage>(); | |
return builder; | |
} | |
} |