如何实现像IAbpSession一样的属性注入?
How to achieve Property Injection like IAbpSession?
我正在尝试实现我自己的自定义 IAbpSession
,但我不知道如何实现与 IAbpSession
相同的 属性 注入。
我的 AppServiceBase
如下所示:
public abstract class EdwardAppServiceBase : ApplicationService
{
public TenantManager TenantManager { get; set; }
public UserManager UserManager { get; set; }
protected EdwardActiveUnitOfWork EdwardActiveUnitOfWork => (EdwardActiveUnitOfWork)UnitOfWorkManager.Current;
protected IEdwardSession EdwardSession { get; set; }
// protected IEdwardSession EdwardSession => AbpSession as IEdwardSession;
protected SensingStoreCloudAppServiceBase()
{
// EdwardSession = NullEdwardSession.Instance;
LocalizationSourceName = SensingStoreCloudConsts.LocalizationSourceName;
}
}
如果我取消注释 EdwardSession = NullEdwardSession.Instance;
,我总是得到 NullEdwardSession
而不是 IEdwardSession
实现:EdwardSession
。
我只能做到AbpSession as IEdwardSession
.
ABP如何注入IAbpSession
并在ApplicationService
中设置其值?
ABP 使用 Castle Windsor 作为依赖并且 property injection:
How properties are injected
Property injection of dependencies is designed to be done during component activation when a component is created. The responsibility of determining which properties are used for injection is fulfilled by default through PropertiesDependenciesModelInspector
- a IContributeComponentModelConstruction
implementation which uses all the following criteria to determine if a property represents a dependency:
- Has 'public' accessible setter
- Is an instance property
- If
ComponentModel.InspectionBehavior
is set to PropertiesInspectionBehavior.DeclaredOnly
, is not inherited
- Does not have parameters
- Is not annotated with the
Castle.Core.DoNotWireAttribute
attribute
所以做到 public
:
// protected IEdwardSession EdwardSession { get; set; }
public IEdwardSession EdwardSession { get; set; }
我正在尝试实现我自己的自定义 IAbpSession
,但我不知道如何实现与 IAbpSession
相同的 属性 注入。
我的 AppServiceBase
如下所示:
public abstract class EdwardAppServiceBase : ApplicationService
{
public TenantManager TenantManager { get; set; }
public UserManager UserManager { get; set; }
protected EdwardActiveUnitOfWork EdwardActiveUnitOfWork => (EdwardActiveUnitOfWork)UnitOfWorkManager.Current;
protected IEdwardSession EdwardSession { get; set; }
// protected IEdwardSession EdwardSession => AbpSession as IEdwardSession;
protected SensingStoreCloudAppServiceBase()
{
// EdwardSession = NullEdwardSession.Instance;
LocalizationSourceName = SensingStoreCloudConsts.LocalizationSourceName;
}
}
如果我取消注释 EdwardSession = NullEdwardSession.Instance;
,我总是得到 NullEdwardSession
而不是 IEdwardSession
实现:EdwardSession
。
我只能做到AbpSession as IEdwardSession
.
ABP如何注入IAbpSession
并在ApplicationService
中设置其值?
ABP 使用 Castle Windsor 作为依赖并且 property injection:
How properties are injected
Property injection of dependencies is designed to be done during component activation when a component is created. The responsibility of determining which properties are used for injection is fulfilled by default through
PropertiesDependenciesModelInspector
- aIContributeComponentModelConstruction
implementation which uses all the following criteria to determine if a property represents a dependency:
- Has 'public' accessible setter
- Is an instance property
- If
ComponentModel.InspectionBehavior
is set toPropertiesInspectionBehavior.DeclaredOnly
, is not inherited- Does not have parameters
- Is not annotated with the
Castle.Core.DoNotWireAttribute
attribute
所以做到 public
:
// protected IEdwardSession EdwardSession { get; set; }
public IEdwardSession EdwardSession { get; set; }