Browse Source

Refactored.

pull/81/head
Halil İbrahim Kalkan 10 years ago
parent
commit
299878a8d4
  1. 2
      src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/IApplicationService.cs
  2. 3
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs
  3. 8
      src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs
  4. 30
      src/Volo.DependencyInjection/Microsoft/Extensions/DependencyInjection/ServiceCollectionRegistrationExtensions.cs
  5. 9
      src/Volo.DependencyInjection/Volo/DependencyInjection/DisableAutoDependencyInjectionRegistrationAttribute.cs
  6. 2
      src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs
  7. 9
      src/Volo.DependencyInjection/Volo/DependencyInjection/SkipAutoRegistrationAttribute.cs

2
src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/IApplicationService.cs

@ -3,7 +3,7 @@
namespace Volo.Abp.Application.Services
{
/// <summary>
/// This interface must be implemented by all application services to identify them by convention.
/// This interface must be implemented by all application services to register and identify them by convention.
/// </summary>
public interface IApplicationService : ITransientDependency
{

3
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs

@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Volo.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc
{
public abstract class AbpController : Controller
public abstract class AbpController : Controller, ITransientDependency
{
}

8
src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs

@ -1,4 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Volo;
using Volo.Abp;
using Volo.DependencyInjection;
@ -6,8 +8,10 @@ namespace Microsoft.AspNetCore.Builder
{
public static class AbpApplicationBuilderExtensions
{
public static void InitializeApplication(this IApplicationBuilder app)
public static void InitializeApplication([NotNull] this IApplicationBuilder app)
{
Check.NotNull(app, nameof(app));
app.ApplicationServices.GetRequiredService<ObjectAccessor<IApplicationBuilder>>().Object = app;
app.ApplicationServices.GetRequiredService<AbpApplication>().Initialize(app.ApplicationServices);
}

30
src/Volo.DependencyInjection/Microsoft/Extensions/DependencyInjection/ServiceCollectionRegistrationExtensions.cs

@ -11,33 +11,35 @@ namespace Microsoft.Extensions.DependencyInjection
public static class ServiceCollectionRegistrationExtensions
{
//TODO: Check if assembly/type is added before or add TryAdd versions of them?
//TODO: Return IServiceCollection from all methods
//TODO: When to use Add, when to use TryAdd? We may think to add conventional interfaces to indicate and attributes to override them.
public static void AddAssemblyOf<T>(this IServiceCollection services)
public static IServiceCollection AddAssemblyOf<T>(this IServiceCollection services)
{
services.AddAssembly(typeof(T).GetTypeInfo().Assembly);
return services.AddAssembly(typeof(T).GetTypeInfo().Assembly);
}
public static void AddAssembly(this IServiceCollection services, Assembly assembly)
public static IServiceCollection AddAssembly(this IServiceCollection services, Assembly assembly)
{
var types = AssemblyHelper.GetAllTypes(assembly).Where(t =>
{
var typeInfo = t.GetTypeInfo();
return typeInfo.IsClass && !typeInfo.IsAbstract && !typeInfo.IsGenericType && !typeInfo.IsDefined(typeof(DisableAutoDependencyInjectionRegistrationAttribute));
return typeInfo.IsClass && !typeInfo.IsAbstract && !typeInfo.IsGenericType && !typeInfo.IsDefined(typeof(SkipAutoRegistrationAttribute));
});
services.AddTypes(types.ToArray());
return services.AddTypes(types.ToArray());
}
public static void AddTypes(this IServiceCollection services, params Type[] types)
public static IServiceCollection AddTypes(this IServiceCollection services, params Type[] types)
{
foreach (var type in types)
{
services.AddType(type);
}
return services;
}
public static void AddType(this IServiceCollection services, Type type)
public static IServiceCollection AddType(this IServiceCollection services, Type type)
{
//TODO: Make this code extensible, so we can add other conventions!
@ -58,9 +60,11 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddScoped(serviceType, type);
}
}
return services;
}
private static List<Type> FindServiceTypes(Type type)
private static IEnumerable<Type> FindServiceTypes(Type type)
{
var customExposedServices = type.GetTypeInfo().GetCustomAttributes().OfType<IExposedServiceTypesProvider>().SelectMany(p => p.GetExposedServiceTypes()).ToList();
if (customExposedServices.Any())
@ -68,9 +72,7 @@ namespace Microsoft.Extensions.DependencyInjection
return customExposedServices;
}
var serviceTypes = new List<Type>();
serviceTypes.Add(type);
var serviceTypes = new List<Type> { type };
foreach (var interfaceType in type.GetTypeInfo().GetInterfaces())
{

9
src/Volo.DependencyInjection/Volo/DependencyInjection/DisableAutoDependencyInjectionRegistrationAttribute.cs

@ -1,9 +0,0 @@
using System;
namespace Volo.DependencyInjection
{
public class DisableAutoDependencyInjectionRegistrationAttribute : Attribute
{
}
}

2
src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs

@ -8,7 +8,7 @@ namespace Volo.DependencyInjection
public ExposeServicesAttribute(params Type[] exposedServiceTypes)
{
ExposedServiceTypes = exposedServiceTypes;
ExposedServiceTypes = exposedServiceTypes ?? new Type[];
}
public Type[] GetExposedServiceTypes()

9
src/Volo.DependencyInjection/Volo/DependencyInjection/SkipAutoRegistrationAttribute.cs

@ -0,0 +1,9 @@
using System;
namespace Volo.DependencyInjection
{
public class SkipAutoRegistrationAttribute : Attribute
{
}
}
Loading…
Cancel
Save