Quantcast
Channel: patterns & practices: Project Silk
Viewing all articles
Browse latest Browse all 93

New Post: IServiceLocator inject at constructor VS ServiceLocator's static member?

$
0
0

Hi,

In my WPF, I could not use constructor injected because of my ViewModel already derrived from other class.

Then I modified the helper code to following by using FullName ServiceLocator.

public class AutoNotificationObject : NotificationObject
    {
        protected T Using() where T : class
        {
            var handler = ServiceLocator.Current.GetInstance<T>();
            if (handler == null)
            {
                throw new BusinessServicesException("Unable to resolve type with service locator: Type" + typeof(T).Name);
            }
            return handler;
        }
    }

 

var

 

handler = ServiceLocator.Current.GetInstance<T>()public AuthorizedController

(IServiceLocator serviceLocator)
        {
            this.serviceLocator = serviceLocator;
        }

What differnt between the two


Viewing all articles
Browse latest Browse all 93

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>