我希望我有一个 PostSharp 驱动的单例模式?
PostSharp可以吗?
是否有现有的示例或项目?
想要这样的东西:
interface ISingleton
{
void Refresh();
object Instance{get;set;}
}
[Singleton(AutoRefresh=true, AutoRefreshInterval=20)]
public class Repository
{
private Repository()
{
//Code to load data...
}
public DoSomething()
{
//Do something at instance level;
}
public void Refresh()
{
//Refresh data
}
}
SingletonAttribute 应该使类实现 ISingleton 并为 Instance Property 和 Refresh() 方法主体插入代码
使用类时:
((Repository as ISingleton).Instance as Repository).DoSomething();