Browse Source

Change some code base on review cmment.

pull/17421/head
maliming 3 years ago
parent
commit
547bb83667
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 8
      framework/src/Volo.Abp.Ddd.Domain/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs
  2. 3
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs
  3. 2
      framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs

8
framework/src/Volo.Abp.Ddd.Domain/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs

@ -84,11 +84,11 @@ public static class ServiceCollectionRepositoryExtensions
bool replaceExisting, bool replaceExisting,
bool isReadOnlyRepository = false) bool isReadOnlyRepository = false)
{ {
var descriptor = ServiceDescriptor.Transient(serviceType, implementationType); ServiceDescriptor descriptor;
if (isReadOnlyRepository) if (isReadOnlyRepository)
{ {
services.AddTransient(implementationType); services.TryAddTransient(implementationType);
descriptor = ServiceDescriptor.Transient(serviceType, provider => descriptor = ServiceDescriptor.Transient(serviceType, provider =>
{ {
var repository = provider.GetRequiredService(implementationType); var repository = provider.GetRequiredService(implementationType);
@ -96,6 +96,10 @@ public static class ServiceCollectionRepositoryExtensions
return repository; return repository;
}); });
} }
else
{
descriptor = ServiceDescriptor.Transient(serviceType, implementationType);
}
if (replaceExisting) if (replaceExisting)
{ {

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

@ -34,8 +34,7 @@ public abstract class BasicRepositoryBase<TEntity> :
public ICancellationTokenProvider CancellationTokenProvider => LazyServiceProvider.LazyGetService<ICancellationTokenProvider>(NullCancellationTokenProvider.Instance); public ICancellationTokenProvider CancellationTokenProvider => LazyServiceProvider.LazyGetService<ICancellationTokenProvider>(NullCancellationTokenProvider.Instance);
public bool IsReadOnly { get; protected set; }
public bool IsReadOnly { get; set; } = false;
protected BasicRepositoryBase() protected BasicRepositoryBase()
{ {

2
framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs

@ -407,7 +407,7 @@ public class RepositoryRegistration_Tests
public class MyTestAggregateRootWithDefaultPkEmptyRepository : IMyTestAggregateRootWithDefaultPkEmptyRepository public class MyTestAggregateRootWithDefaultPkEmptyRepository : IMyTestAggregateRootWithDefaultPkEmptyRepository
{ {
public bool IsReadOnly { get; set; } = false; public bool IsReadOnly { get; set; }
} }
public class TestDbContextRegistrationOptions : AbpCommonDbContextRegistrationOptions public class TestDbContextRegistrationOptions : AbpCommonDbContextRegistrationOptions

Loading…
Cancel
Save