.xml配置
<!--我们在Object.xml文件上将HexuObjectPostProcessor注册到上下文对象中去-->
<object id="hexu" type="CnblogLesson_4_7.Model.Person,HRABLL" init-method="Init" destroy-method="Destroy"/>
<object type="CnblogLesson_4_7.HexuObjectPostProcessor,HRABLL"/>
.代码
namespace CnblogLesson_4_7
{
public class HexuObjectPostProcessor : IObjectPostProcessor
{
public object PostProcessAfterInitialization(object instance, string objectName)
{ if (objectName.EndsWith("SysDictTypeDao"))
{
return Activator.CreateInstance(typeof(SysDictTypeDao));
} Console.WriteLine("我调用了对象后处理器的 PostProcessAfterInitialization 方法,当前的对象是{0}", objectName);
return instance; } public object PostProcessBeforeInitialization(object instance, string name)
{
Console.WriteLine("我调用了对象后处理器的 PostProcessBeforeInitialization 方法,当前的对象是{0}", name);
return instance;
}
} }