mirror of https://github.com/abpframework/abp.git
11 changed files with 202 additions and 294 deletions
@ -1,43 +1,31 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.DependencyInjection |
|||
{ |
|||
public class AbpWebAssemblyConventionalRegistrar : ConventionalRegistrarBase |
|||
public class AbpWebAssemblyConventionalRegistrar : DefaultConventionalRegistrar |
|||
{ |
|||
public override void AddType(IServiceCollection services, Type type) |
|||
protected override bool IsConventionalRegistrationDisabled(Type type) |
|||
{ |
|||
if (IsConventionalRegistrationDisabled(type)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
if (!IsComponent(type)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var serviceTypes = ExposedServiceExplorer.GetExposedServices(type); |
|||
|
|||
TriggerServiceExposing(services, type, serviceTypes); |
|||
|
|||
foreach (var serviceType in serviceTypes) |
|||
{ |
|||
services.Add( |
|||
ServiceDescriptor.Describe( |
|||
serviceType, |
|||
type, |
|||
ServiceLifetime.Transient |
|||
) |
|||
); |
|||
} |
|||
return !IsComponent(type) || base.IsConventionalRegistrationDisabled(type); |
|||
} |
|||
|
|||
private static bool IsComponent(Type type) |
|||
{ |
|||
return typeof(ComponentBase).IsAssignableFrom(type); |
|||
} |
|||
|
|||
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute) |
|||
{ |
|||
return dependencyAttribute?.Lifetime ?? GetWebAssemblyServiceLifetime(type); |
|||
} |
|||
|
|||
protected virtual ServiceLifetime GetWebAssemblyServiceLifetime(Type type) |
|||
{ |
|||
return ServiceLifetime.Transient; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,43 +1,31 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.SignalR |
|||
{ |
|||
public class AbpSignalRConventionalRegistrar : ConventionalRegistrarBase |
|||
public class AbpSignalRConventionalRegistrar : DefaultConventionalRegistrar |
|||
{ |
|||
public override void AddType(IServiceCollection services, Type type) |
|||
protected override bool IsConventionalRegistrationDisabled(Type type) |
|||
{ |
|||
if (IsConventionalRegistrationDisabled(type)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
if (!IsHub(type)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var serviceTypes = ExposedServiceExplorer.GetExposedServices(type); |
|||
|
|||
TriggerServiceExposing(services, type, serviceTypes); |
|||
|
|||
foreach (var serviceType in serviceTypes) |
|||
{ |
|||
services.Add( |
|||
ServiceDescriptor.Describe( |
|||
serviceType, |
|||
type, |
|||
ServiceLifetime.Transient |
|||
) |
|||
); |
|||
} |
|||
return !IsHub(type) || base.IsConventionalRegistrationDisabled(type); |
|||
} |
|||
|
|||
|
|||
private static bool IsHub(Type type) |
|||
{ |
|||
return typeof(Hub).IsAssignableFrom(type); |
|||
} |
|||
|
|||
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute) |
|||
{ |
|||
return dependencyAttribute?.Lifetime ?? GetSignalRServiceLifetime(type); |
|||
} |
|||
|
|||
protected virtual ServiceLifetime GetSignalRServiceLifetime(Type type) |
|||
{ |
|||
return ServiceLifetime.Transient; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,27 +1,21 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BackgroundWorkers.Quartz |
|||
{ |
|||
public class AbpQuartzConventionalRegistrar : DefaultConventionalRegistrar |
|||
{ |
|||
public override void AddType(IServiceCollection services, Type type) |
|||
protected override bool IsConventionalRegistrationDisabled(Type type) |
|||
{ |
|||
if (!typeof(IQuartzBackgroundWorker).IsAssignableFrom(type)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var dependencyAttribute = GetDependencyAttributeOrNull(type); |
|||
var lifeTime = GetLifeTimeOrNull(type, dependencyAttribute); |
|||
|
|||
if (lifeTime == null) |
|||
{ |
|||
return; |
|||
} |
|||
return !typeof(IQuartzBackgroundWorker).IsAssignableFrom(type) || base.IsConventionalRegistrationDisabled(type); |
|||
} |
|||
|
|||
services.Add(ServiceDescriptor.Describe(typeof(IQuartzBackgroundWorker), type, lifeTime.Value)); |
|||
protected override List<Type> GetExposedServiceTypes(Type type) |
|||
{ |
|||
var serviceTypes = base.GetExposedServiceTypes(type); |
|||
serviceTypes.AddIfNotContains(typeof(IQuartzBackgroundWorker)); |
|||
return serviceTypes; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,29 +1,25 @@ |
|||
using System; |
|||
using System.Reflection; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.DependencyInjection.Extensions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.MongoDB.DependencyInjection |
|||
{ |
|||
public class AbpMongoDbConventionalRegistrar : DefaultConventionalRegistrar |
|||
{ |
|||
public override void AddType(IServiceCollection services, Type type) |
|||
protected override bool IsConventionalRegistrationDisabled(Type type) |
|||
{ |
|||
if (!typeof(IAbpMongoDbContext).IsAssignableFrom(type) || type == typeof(AbpMongoDbContext)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var dependencyAttribute = GetDependencyAttributeOrNull(type); |
|||
var lifeTime = GetLifeTimeOrNull(type, dependencyAttribute); |
|||
return !typeof(IAbpMongoDbContext).IsAssignableFrom(type) || type == typeof(AbpMongoDbContext) || base.IsConventionalRegistrationDisabled(type); |
|||
} |
|||
|
|||
if (lifeTime == null) |
|||
{ |
|||
return; |
|||
} |
|||
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute) |
|||
{ |
|||
return dependencyAttribute?.Lifetime ?? GetAbpMongoDbContextLifetime(type); |
|||
} |
|||
|
|||
services.Add(ServiceDescriptor.Describe(typeof(IAbpMongoDbContext), type, ServiceLifetime.Transient)); |
|||
protected virtual ServiceLifetime GetAbpMongoDbContextLifetime(Type type) |
|||
{ |
|||
return ServiceLifetime.Transient; |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue