Browse Source

Resolved #6677: Do not register repository classes to dependency injection by default.

pull/6678/head
Halil İbrahim Kalkan 6 years ago
parent
commit
73311b0c3d
  1. 13
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs
  2. 9
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/AbpDddDomainModule.cs
  3. 41
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/AbpRepositoryConventionalRegistrar.cs
  4. 9
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs

13
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs

@ -26,7 +26,7 @@ namespace Volo.Abp.DependencyInjection
return;
}
var exposedServiceTypes = ExposedServiceExplorer.GetExposedServices(type);
var exposedServiceTypes = GetExposedServiceTypes(type);
TriggerServiceExposing(services, type, exposedServiceTypes);
@ -54,6 +54,11 @@ namespace Volo.Abp.DependencyInjection
}
}
protected virtual List<Type> GetExposedServiceTypes(Type type)
{
return ExposedServiceExplorer.GetExposedServices(type);
}
protected virtual ServiceDescriptor CreateServiceDescriptor(
Type implementationType,
Type exposingServiceType,
@ -117,10 +122,10 @@ namespace Volo.Abp.DependencyInjection
protected virtual ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute)
{
return dependencyAttribute?.Lifetime ?? GetServiceLifetimeFromClassHierarcy(type);
return dependencyAttribute?.Lifetime ?? GetServiceLifetimeFromClassHierarchy(type);
}
protected virtual ServiceLifetime? GetServiceLifetimeFromClassHierarcy(Type type)
protected virtual ServiceLifetime? GetServiceLifetimeFromClassHierarchy(Type type)
{
if (typeof(ITransientDependency).GetTypeInfo().IsAssignableFrom(type))
{
@ -140,4 +145,4 @@ namespace Volo.Abp.DependencyInjection
return null;
}
}
}
}

9
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/AbpDddDomainModule.cs

@ -1,5 +1,7 @@
using Volo.Abp.Auditing;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Guids;
@ -28,6 +30,9 @@ namespace Volo.Abp.Domain
)]
public class AbpDddDomainModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddConventionalRegistrar(new AbpRepositoryConventionalRegistrar());
}
}
}

41
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/AbpRepositoryConventionalRegistrar.cs

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Domain.Repositories
{
public class AbpRepositoryConventionalRegistrar : DefaultConventionalRegistrar
{
public static bool ExposeRepositoryClasses { get; set; }
protected override bool IsConventionalRegistrationDisabled(Type type)
{
if (!typeof(IRepository).IsAssignableFrom(type))
{
return false;
}
return base.IsConventionalRegistrationDisabled(type);
}
protected override List<Type> GetExposedServiceTypes(Type type)
{
if (ExposeRepositoryClasses)
{
return base.GetExposedServiceTypes(type);
}
return base.GetExposedServiceTypes(type)
.Where(x => x.IsInterface)
.ToList();
}
protected override ServiceLifetime? GetServiceLifetimeFromClassHierarchy(Type type)
{
return base.GetServiceLifetimeFromClassHierarchy(type) ??
ServiceLifetime.Transient;
}
}
}

9
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs

@ -9,11 +9,10 @@ using Volo.Abp.Uow;
namespace Volo.Abp.Domain.Repositories
{
public abstract class BasicRepositoryBase<TEntity> :
IBasicRepository<TEntity>,
public abstract class BasicRepositoryBase<TEntity> :
IBasicRepository<TEntity>,
IServiceProviderAccessor,
IUnitOfWorkEnabled,
ITransientDependency
IUnitOfWorkEnabled
where TEntity : class, IEntity
{
public IServiceProvider ServiceProvider { get; set; }
@ -59,7 +58,7 @@ namespace Volo.Abp.Domain.Repositories
}
public abstract Task<TEntity> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);
public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
var entity = await FindAsync(id, cancellationToken: cancellationToken);

Loading…
Cancel
Save