PIAB: Singleton Best Practices?

Topics: Policy Injection Application Block
Apr 17, 2007 at 7:41 PM
If I have a service that is a singleton with policies attached to it, it sound like I only have to create the service only once because the handlers are reusable. Hence this is acceptable:

public static class Services
    private static INewsService _newsService = PolicyInjection.Create<NewsService,INewsService>();
    public static INewsService GetNewsService()
        return _newsService;

and may actually have some performance benefits of only creating the TransparentProxy once.

Is this indeed acceptable and perhaps a good practice?




David Hayden
Microsoft MVP C#
Apr 17, 2007 at 8:09 PM
Yes, this is fine. I wouldn't want to speculate on the performance impacts, but sematically this will do exactly what you expect.