#5930 Initial AbpComponentBase

pull/5966/head
Halil İbrahim Kalkan 5 years ago
parent c8c1e5b936
commit cc5ba6cd56

@ -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>

@ -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)

@ -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;
}
}
}

@ -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