Browse Source

#5930 Initial AbpComponentBase

pull/5966/head
Halil İbrahim Kalkan 6 years ago
parent
commit
cc5ba6cd56
  1. 2
      framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj
  2. 4
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpAspNetCoreComponentsModule.cs
  3. 48
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs
  4. 43
      framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs

2
framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj

@ -15,7 +15,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.ObjectMapping\Volo.Abp.ObjectMapping.csproj" />
</ItemGroup>
<ItemGroup>

4
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpAspNetCoreComponentsModule.cs

@ -3,9 +3,13 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Components.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Modularity;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.AspNetCore.Components
{
[DependsOn(
typeof(AbpObjectMappingModule)
)]
public class AbpAspNetCoreComponentsModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)

48
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs

@ -0,0 +1,48 @@
using System;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.AspNetCore.Components
{
public class AbpComponentBase : OwningComponentBase
{
//TODO: IStringLocalizer, CurrentUser, Logger, AuthorizationService
protected IObjectMapper ObjectMapper
{
get
{
if (_objectMapper != null)
{
return _objectMapper;
}
if (ObjectMapperContext == null)
{
return LazyGetRequiredService(ref _objectMapper);
}
return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
ref _objectMapper
);
}
}
private IObjectMapper _objectMapper;
protected Type ObjectMapperContext { get; set; }
protected TService LazyGetRequiredService<TService>(ref TService reference) => LazyGetRequiredService(typeof(TService), ref reference);
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)ScopedServices.GetRequiredService(serviceType);
}
return reference;
}
}
}

43
framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs

@ -12,6 +12,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Components;
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.Authorization;
using Volo.Abp.ObjectMapping;
@ -151,7 +152,7 @@ namespace Volo.Abp.BlazoriseUI
TListViewModel,
TCreateViewModel,
TUpdateViewModel>
: OwningComponentBase
: AbpComponentBase
where TAppService : ICrudAppService<
TGetOutputDto,
TGetListOutputDto,
@ -195,44 +196,6 @@ namespace Volo.Abp.BlazoriseUI
public bool HasUpdatePermission { get; set; }
public bool HasDeletePermission { get; set; }
protected Type ObjectMapperContext { get; set; }
protected IObjectMapper ObjectMapper
{
get
{
if (_objectMapper != null)
{
return _objectMapper;
}
if (ObjectMapperContext == null)
{
return LazyGetRequiredService(ref _objectMapper);
}
return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
ref _objectMapper
);
}
}
private IObjectMapper _objectMapper;
protected TService LazyGetRequiredService<TService>(ref TService reference)
=> LazyGetRequiredService(typeof(TService), ref reference);
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)ScopedServices.GetRequiredService(serviceType);
}
return reference;
}
protected AbpCrudPageBase()
{
NewEntity = new TCreateViewModel();
@ -297,7 +260,7 @@ namespace Volo.Abp.BlazoriseUI
{
limitedResultRequestInput.MaxResultCount = PageSize;
}
return Task.CompletedTask;
}

Loading…
Cancel
Save