Browse Source

Refactor namings.

pull/96/head
Halil İbrahim Kalkan 9 years ago
parent
commit
bec0f6bec2
  1. 4
      src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs
  2. 2
      src/Volo.Abp/Microsoft/Extensions/DependencyInjection/IOnServiceRegistredContext.cs
  3. 4
      src/Volo.Abp/Microsoft/Extensions/DependencyInjection/OnServiceRegistredContext.cs
  4. 20
      src/Volo.Abp/Microsoft/Extensions/DependencyInjection/ServiceCollectionRegistrationActionExtensions.cs
  5. 17
      src/Volo.Abp/Volo/Abp/AbpKernelModule.cs
  6. 15
      src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkAttribute.cs
  7. 16
      src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkInterceptor.cs
  8. 6
      src/Volo.Abp/Volo/DependencyInjection/AutoRegistrationHelper.cs
  9. 2
      src/Volo.Abp/Volo/DependencyInjection/IServiceExposingArgs.cs
  10. 4
      src/Volo.Abp/Volo/DependencyInjection/OnServiceExposingArgs.cs
  11. 2
      src/Volo.Abp/Volo/DependencyInjection/ServiceExposingActionList.cs
  12. 2
      src/Volo.Abp/Volo/DependencyInjection/ServiceRegistrationActionList.cs
  13. 2
      test/Volo.Abp.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs

4
src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs

@ -21,9 +21,9 @@ namespace Autofac.Builder
return registrationBuilder; return registrationBuilder;
} }
var serviceRegistredArgs = new OnServiceRegistredArgs(serviceType); var serviceRegistredArgs = new OnServiceRegistredContext(serviceType);
foreach (var registrationAction in services.GetServiceRegistrationActionList()) foreach (var registrationAction in services.GetRegistrationActionList())
{ {
registrationAction.Invoke(serviceRegistredArgs); registrationAction.Invoke(serviceRegistredArgs);
} }

2
src/Volo.Abp/Microsoft/Extensions/DependencyInjection/IOnServiceRegistredArgs.cs → src/Volo.Abp/Microsoft/Extensions/DependencyInjection/IOnServiceRegistredContext.cs

@ -4,7 +4,7 @@ using Volo.Abp.DynamicProxy;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
public interface IOnServiceRegistredArgs public interface IOnServiceRegistredContext
{ {
ITypeList<IAbpInterceptor> Interceptors { get; } ITypeList<IAbpInterceptor> Interceptors { get; }

4
src/Volo.Abp/Microsoft/Extensions/DependencyInjection/OnServiceRegistredArgs.cs → src/Volo.Abp/Microsoft/Extensions/DependencyInjection/OnServiceRegistredContext.cs

@ -6,13 +6,13 @@ using Volo.Abp.DynamicProxy;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
public class OnServiceRegistredArgs : IOnServiceRegistredArgs public class OnServiceRegistredContext : IOnServiceRegistredContext
{ {
public virtual ITypeList<IAbpInterceptor> Interceptors { get; } public virtual ITypeList<IAbpInterceptor> Interceptors { get; }
public virtual Type ImplementationType { get; } public virtual Type ImplementationType { get; }
public OnServiceRegistredArgs([NotNull] Type implementationType) public OnServiceRegistredContext([NotNull] Type implementationType)
{ {
ImplementationType = Check.NotNull(implementationType, nameof(implementationType)); ImplementationType = Check.NotNull(implementationType, nameof(implementationType));

20
src/Volo.Abp/Microsoft/Extensions/DependencyInjection/ServiceCollectionRegistrationActionExtensions.cs

@ -5,17 +5,17 @@ namespace Microsoft.Extensions.DependencyInjection
{ {
public static class ServiceCollectionRegistrationActionExtensions public static class ServiceCollectionRegistrationActionExtensions
{ {
public static void OnServiceRegistred(this IServiceCollection services, Action<IOnServiceRegistredArgs> registrationAction) public static void OnRegistred(this IServiceCollection services, Action<IOnServiceRegistredContext> registrationAction)
{ {
GetOrCreateServiceActionList(services).Add(registrationAction); GetOrCreateRegistrationActionList(services).Add(registrationAction);
} }
public static ServiceRegistrationActionList GetServiceRegistrationActionList(this IServiceCollection services) public static ServiceRegistrationActionList GetRegistrationActionList(this IServiceCollection services)
{ {
return GetOrCreateServiceActionList(services); return GetOrCreateRegistrationActionList(services);
} }
private static ServiceRegistrationActionList GetOrCreateServiceActionList(IServiceCollection services) private static ServiceRegistrationActionList GetOrCreateRegistrationActionList(IServiceCollection services)
{ {
var actionList = services.GetSingletonInstanceOrNull<IObjectAccessor<ServiceRegistrationActionList>>()?.Value; var actionList = services.GetSingletonInstanceOrNull<IObjectAccessor<ServiceRegistrationActionList>>()?.Value;
if (actionList == null) if (actionList == null)
@ -27,17 +27,17 @@ namespace Microsoft.Extensions.DependencyInjection
return actionList; return actionList;
} }
public static void OnServiceExposing(this IServiceCollection services, Action<IOnServiceExposingArgs> exposeAction) public static void OnExposing(this IServiceCollection services, Action<IOnServiceExposingContext> exposeAction)
{ {
GetOrCreateOnServiceExposingList(services).Add(exposeAction); GetOrCreateExposingList(services).Add(exposeAction);
} }
public static ServiceExposingActionList GetServiceExposingActionList(this IServiceCollection services) public static ServiceExposingActionList GetExposingActionList(this IServiceCollection services)
{ {
return GetOrCreateOnServiceExposingList(services); return GetOrCreateExposingList(services);
} }
private static ServiceExposingActionList GetOrCreateOnServiceExposingList(IServiceCollection services) private static ServiceExposingActionList GetOrCreateExposingList(IServiceCollection services)
{ {
var actionList = services.GetSingletonInstanceOrNull<IObjectAccessor<ServiceExposingActionList>>()?.Value; var actionList = services.GetSingletonInstanceOrNull<IObjectAccessor<ServiceExposingActionList>>()?.Value;
if (actionList == null) if (actionList == null)

17
src/Volo.Abp/Volo/Abp/AbpKernelModule.cs

@ -1,7 +1,5 @@
using System; using System;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Application.Services;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
using Volo.Abp.Reflection; using Volo.Abp.Reflection;
@ -14,17 +12,10 @@ namespace Volo.Abp
{ {
public override void PreConfigureServices(IServiceCollection services) public override void PreConfigureServices(IServiceCollection services)
{ {
//TODO: Move these to dedicated class(es) services.OnRegistred(UnitOfWorkInterceptorRegistrar.RegisterIfNeeded);
services.OnServiceRegistred(registration => //TODO: Move to a dedicated class
{ services.OnExposing(context =>
if (typeof(IApplicationService).GetTypeInfo().IsAssignableFrom(registration.ImplementationType))
{
registration.Interceptors.Add<UnitOfWorkInterceptor>();
}
});
services.OnServiceExposing(context =>
{ {
context.ExposedTypes.AddRange( context.ExposedTypes.AddRange(
ReflectionHelper.GetImplementedGenericTypes( ReflectionHelper.GetImplementedGenericTypes(

15
src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkAttribute.cs

@ -0,0 +1,15 @@
using System;
namespace Volo.Abp.Uow
{
/// <summary>
/// Used to indicate that declaring method (or all methods of the class) is atomic and should be considered as a unit of work (UOW).
/// </summary>
/// <remarks>
/// This attribute has no effect if there is already a unit of work before calling this method. It uses the ambient UOW in this case.
/// </remarks>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface)]
public class UnitOfWorkAttribute : Attribute
{
}
}

16
src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkInterceptor.cs

@ -1,9 +1,23 @@
using System.Threading.Tasks; using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Application.Services;
using Volo.Abp.DynamicProxy; using Volo.Abp.DynamicProxy;
using Volo.DependencyInjection; using Volo.DependencyInjection;
namespace Volo.Abp.Uow namespace Volo.Abp.Uow
{ {
public static class UnitOfWorkInterceptorRegistrar
{
public static void RegisterIfNeeded(IOnServiceRegistredContext context)
{
if (typeof(IApplicationService).GetTypeInfo().IsAssignableFrom(context.ImplementationType))
{
context.Interceptors.Add<UnitOfWorkInterceptor>();
}
}
}
public class UnitOfWorkInterceptor : AbpInterceptor, ITransientDependency public class UnitOfWorkInterceptor : AbpInterceptor, ITransientDependency
{ {
private readonly IUnitOfWorkManager _unitOfWorkManager; private readonly IUnitOfWorkManager _unitOfWorkManager;

6
src/Volo.Abp/Volo/DependencyInjection/AutoRegistrationHelper.cs

@ -48,11 +48,11 @@ namespace Volo.DependencyInjection
} }
} }
var exposeActions = services.GetServiceExposingActionList(); var exposeActions = services.GetExposingActionList();
if (exposeActions.Any()) if (exposeActions.Any())
{ {
var args = new OnServiceExposingArgs(type, serviceTypes); var args = new OnServiceExposingContext(type, serviceTypes);
foreach (var action in services.GetServiceExposingActionList()) foreach (var action in services.GetExposingActionList())
{ {
action(args); action(args);
} }

2
src/Volo.Abp/Volo/DependencyInjection/IServiceExposingArgs.cs

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Volo.DependencyInjection namespace Volo.DependencyInjection
{ {
public interface IOnServiceExposingArgs public interface IOnServiceExposingContext
{ {
Type ImplementationType { get; } Type ImplementationType { get; }

4
src/Volo.Abp/Volo/DependencyInjection/OnServiceExposingArgs.cs

@ -4,13 +4,13 @@ using JetBrains.Annotations;
namespace Volo.DependencyInjection namespace Volo.DependencyInjection
{ {
public class OnServiceExposingArgs : IOnServiceExposingArgs public class OnServiceExposingContext : IOnServiceExposingContext
{ {
public Type ImplementationType { get; } public Type ImplementationType { get; }
public List<Type> ExposedTypes { get; } public List<Type> ExposedTypes { get; }
public OnServiceExposingArgs([NotNull] Type implementationType, List<Type> exposedTypes) public OnServiceExposingContext([NotNull] Type implementationType, List<Type> exposedTypes)
{ {
ImplementationType = Check.NotNull(implementationType, nameof(implementationType)); ImplementationType = Check.NotNull(implementationType, nameof(implementationType));
ExposedTypes = Check.NotNull(exposedTypes, nameof(exposedTypes)); ExposedTypes = Check.NotNull(exposedTypes, nameof(exposedTypes));

2
src/Volo.Abp/Volo/DependencyInjection/ServiceExposingActionList.cs

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Volo.DependencyInjection namespace Volo.DependencyInjection
{ {
public class ServiceExposingActionList : List<Action<IOnServiceExposingArgs>> public class ServiceExposingActionList : List<Action<IOnServiceExposingContext>>
{ {
} }

2
src/Volo.Abp/Volo/DependencyInjection/ServiceRegistrationActionList.cs

@ -4,7 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace Volo.DependencyInjection namespace Volo.DependencyInjection
{ {
public class ServiceRegistrationActionList : List<Action<IOnServiceRegistredArgs>> public class ServiceRegistrationActionList : List<Action<IOnServiceRegistredContext>>
{ {
} }

2
test/Volo.Abp.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs

@ -20,7 +20,7 @@ namespace Volo.Abp.DynamicProxy
services.AddTransient<SimpleResultCacheTestInterceptor>(); services.AddTransient<SimpleResultCacheTestInterceptor>();
services.AddTransient<CachedTestObject>(); services.AddTransient<CachedTestObject>();
services.OnServiceRegistred(registration => services.OnRegistred(registration =>
{ {
if (typeof(SimpleInterceptionTargetClass) == registration.ImplementationType) if (typeof(SimpleInterceptionTargetClass) == registration.ImplementationType)
{ {

Loading…
Cancel
Save