Guest User

Untitled

a guest
Nov 16th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. private readonly IService _Service;
  2. public LoginViewModel(IService Service=null) //Also i want to make this innjection optional so i set it to NULL
  3. {
  4. _Service = Service;
  5. }
  6.  
  7. private void MethodWhereIWantToUseService()
  8. {
  9. //_service is coming NULL because configuration or mapping of injection calls after this
  10. _Service.MYMethod();
  11. }
  12.  
  13. public class ServicesModule : IModule
  14. {
  15. public void Initialize()
  16. {
  17. var container = ServiceLocator.Current.GetInstance<IUnityContainer>();
  18. container.RegisterType<IService, Service>();
  19.  
  20. }
  21. }
  22.  
  23. public class Bootstrapper : UnityBootstrapper
  24. {
  25. protected override void ConfigureModuleCatalog()
  26. {
  27. base.ConfigureModuleCatalog();
  28. ModuleCatalog catalog = (ModuleCatalog)this.ModuleCatalog;
  29. catalog.AddModule(typeof(ServicesModule));
  30.  
  31. }
  32. }
Add Comment
Please, Sign In to add comment