mirror of https://github.com/abpframework/abp.git
11 changed files with 130 additions and 460 deletions
@ -1,55 +1,22 @@ |
|||||
using System; |
using System; |
||||
using Microsoft.AspNetCore.Mvc; |
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
using Volo.Abp.ObjectMapping; |
using Volo.Abp.ObjectMapping; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc |
namespace Volo.Abp.AspNetCore.Mvc |
||||
{ |
{ |
||||
public abstract class AbpViewComponent : ViewComponent |
public abstract class AbpViewComponent : ViewComponent |
||||
{ |
{ |
||||
public IServiceProvider ServiceProvider { get; set; } |
public IAbpLazyServiceProvider LazyServiceProvider { get; set; } |
||||
protected readonly object ServiceProviderLock = new object(); |
|
||||
|
|
||||
protected TService LazyGetRequiredService<TService>(ref TService reference) |
|
||||
=> LazyGetRequiredService(typeof(TService), ref reference); |
|
||||
|
|
||||
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference) |
|
||||
{ |
|
||||
if (reference == null) |
|
||||
{ |
|
||||
lock (ServiceProviderLock) |
|
||||
{ |
|
||||
if (reference == null) |
|
||||
{ |
|
||||
reference = (TRef)ServiceProvider.GetRequiredService(serviceType); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return reference; |
public IServiceProvider ServiceProvider { get; set; } |
||||
} |
|
||||
|
|
||||
protected Type ObjectMapperContext { 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( |
protected IObjectMapper ObjectMapper => LazyServiceProvider.LazyGetService<IObjectMapper>(provider => |
||||
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext), |
ObjectMapperContext == null |
||||
ref _objectMapper |
? provider.GetRequiredService<IObjectMapper>() |
||||
); |
: (IObjectMapper) provider.GetRequiredService(typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext))); |
||||
} |
|
||||
} |
|
||||
private IObjectMapper _objectMapper; |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue