Maui blazor 项目: program:
public static class MauiProgram {
public static MauiApp CreateMauiApp() {
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts => {
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
builder.Services.AddMauiBlazorWebView();
ConfigureConfiguration(builder);
builder.Services.AddApplication<KkdQueuingServiceMauiModule>(options => {
options.Services.ReplaceConfiguration(builder.Configuration);
options.UseAutofac();
});
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug();
#endif
var app = builder.Build();
var abpApplication = app.Services.GetRequiredService<IAbpApplicationWithExternalServiceProvider>();
abpApplication.Initialize(app.Services);
return app;
}
private static void ConfigureConfiguration(MauiAppBuilder builder) {
var assembly = typeof(App).GetTypeInfo().Assembly;
builder.Configuration.AddJsonFile(new EmbeddedFileProvider(assembly), "appsettings.json", false, false);
builder.Configuration.AddJsonFile(new EmbeddedFileProvider(assembly), "appsettings.secrets.json", true, false);
}
}
module:
[DependsOn(typeof(AbpAutofacModule),
typeof(AbpAutoMapperModule),
typeof(AbpAspNetCoreMvcClientCommonModule),
typeof(AbpAspNetCoreComponentsWebModule),
typeof(AbpIdentityProDomainSharedModule),
typeof(AbpIdentityHttpApiClientModule),
typeof(QueuingServiceHttpApiClientModule),
typeof(AbpHttpClientIdentityModelModule))]
public class KkdQueuingServiceMauiModule : AbpModule {
public override void ConfigureServices(ServiceConfigurationContext context) {
context.Services.AddBlazorWebView();
context.Services.AddTransient<IRemoteServiceHttpClientAuthenticator, KkdRemoteServiceHttpClientAuthenticator>();
ConfigureAutoMapper();
base.ConfigureServices(context);
}
private void ConfigureAutoMapper() {
Configure<AbpAutoMapperOptions>(options => {
options.AddMaps<KkdQueuingServiceMauiModule>();
});
}
}
调用:
@page "/counter"
@using Kkd.QueuingService.Commodities
@using Volo.Abp.DependencyInjection
@inject ICommoditiesAppService CommoditiesAppService
@inject IAbpLazyServiceProvider LazyServiceProvider
@code {
private int _currentCount;
private void IncrementCount() {
_currentCount++;
}
private async Task GetCommoditiesAsync() {
try {
var tenantId = new Guid("3a1a22c2-ccbb-3f27-da9d-6e69edade96b");
var getCommoditiesInput = new GetCommoditiesInput();
// 出错代码
var commodities = await CommoditiesAppService.GetListByTenantAsync(tenantId, getCommoditiesInput);
Console.WriteLine($"Commodities count: {commodities.Count}");
}
catch (Exception ex) {
Console.WriteLine($"Error fetching commodities: {ex.Message}");
}
}
}
How to use ABP Commercial in MaUI Blazor?
Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.
If you're creating a bug/problem report, please include followings:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Unable to set property 'Color' on object of type 'Blazorise.Bootstrap5.Button'. The error was: Specified cast is not valid.
System.InvalidOperationException: Unable to set property 'Color' on object of type 'Blazorise.Bootstrap5.Button'. The error was: Specified cast is not valid.
---> System.InvalidCastException: Specified cast is not valid.
at Microsoft.AspNetCore.Components.Reflection.PropertySetter.CallPropertySetter[Button,Color](Action`2 setter, Object target, Object value)
at Microsoft.AspNetCore.Components.Reflection.PropertySetter.SetValue(Object target, Object value)
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.<SetProperties>g__SetProperty|3_0(Object target, PropertySetter writer, String parameterName, Object value)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.<SetProperties>g__SetProperty|3_0(Object target, PropertySetter writer, String parameterName, Object value)
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
at Microsoft.AspNetCore.Components.ParameterView.SetParameterProperties(Object target)
at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
at Blazorise.BaseComponent.SetParametersAsync(ParameterView parameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)