mirror of https://github.com/abpframework/abp.git
6 changed files with 75 additions and 12 deletions
@ -1,9 +1,8 @@ |
|||||
using Microsoft.AspNetCore.Mvc; |
using Microsoft.AspNetCore.Mvc; |
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc |
namespace Volo.Abp.AspNetCore.Mvc |
||||
{ |
{ |
||||
public abstract class AbpViewComponent : ViewComponent, ITransientDependency |
public abstract class AbpViewComponent : ViewComponent |
||||
{ |
{ |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,45 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.AspNetCore.Mvc.RazorPages; |
||||
|
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.DependencyInjection |
||||
|
{ |
||||
|
public class AbpAspNetCoreMvcConventionalRegistrar : DefaultConventionalRegistrar |
||||
|
{ |
||||
|
protected override ServiceLifetime? GetServiceLifetimeFromClassHierarcy(Type type) |
||||
|
{ |
||||
|
var lifeTime = base.GetServiceLifetimeFromClassHierarcy(type); |
||||
|
if (lifeTime != null) |
||||
|
{ |
||||
|
return lifeTime; |
||||
|
} |
||||
|
|
||||
|
if (IsController(type) || |
||||
|
IsPageModel(type) || |
||||
|
IsViewComponent(type)) |
||||
|
{ |
||||
|
return ServiceLifetime.Transient; |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
private static bool IsPageModel(Type type) |
||||
|
{ |
||||
|
return typeof(PageModel).IsAssignableFrom(type) || type.IsDefined(typeof(PageModelAttribute), true); |
||||
|
} |
||||
|
|
||||
|
private static bool IsController(Type type) |
||||
|
{ |
||||
|
return typeof(Controller).IsAssignableFrom(type) || type.IsDefined(typeof(ControllerAttribute), true); |
||||
|
} |
||||
|
|
||||
|
private static bool IsViewComponent(Type type) |
||||
|
{ |
||||
|
return typeof(ViewComponent).IsAssignableFrom(type) || type.IsDefined(typeof(ViewComponentAttribute), true); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue