service-locator

Singleton Vs ServiceLocator

杀马特。学长 韩版系。学妹 提交于 2019-11-29 03:45:26
问题 What are the advantages and disadvantages of using a Service Locator versus a singleton? I've read that singletons are bad but I'm wondering if s Service Locator would be generally a better way of doing things. 回答1: Both approaches are bad in that it's not obvious from class contract what are its' dependencies. That is, private void foo() { var x = SomeSingleton.Instance.GetX(); var y = ServiceLocator.GetService<IProvider>().GetY(); } has references to SomeSingleton and IProvider buried deep

ZF2 when to use getServiceLocator() and when not to

十年热恋 提交于 2019-11-28 21:36:41
问题 I am really confused on when to use getServiceLocator and when not to. As an example: + Module -+ Helloworld --+ src ---+ Controller ----+ IndexController.php ----+ IndexControllerFactory.php ---+ Service ----+ LogginService.php ----+ GreetingService.php ----+ GreetingServiceFactory.php GreetingServiceFactory.php has the content: <?php namespace Helloworld\Service; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; class GreetingServiceFactory

What is the difference between using the Service Locator anti-pattern and using the Castle Windsor container?\" [closed]

℡╲_俬逩灬. 提交于 2019-11-28 09:23:48
Recently, I have been trying to understand what is the difference between using the Service Locator "anti-pattern" and using the Castle Windsor container. I have found some info here and there on the Internet and I have summarized what I have learned so far in an unfinished blog post . EDIT: Until now I have been thinking that Dependency Injection is all one would need to guarantee separation. But everywhere I look I see a push in the direction of containers such as Castle Windsor. I would like to clearly understand the reasons. Please... Explain this to me like I'm a 6 year old :) Mark

How to avoid Service Locator Anti-Pattern?

て烟熏妆下的殇ゞ 提交于 2019-11-27 23:30:48
问题 I'm trying to remove a Service Locator from an abstract base class, but I'm not sure what to replace it with. Here is a psuedo-example of what I've got: public abstract class MyController : Controller { protected IKernel kernel; public MyController(IKernel kernel) { this.kernel = kernel); } protected void DoActions(Type[] types) { MySpecialResolver resolver = new MySpecialResolver(kernel); foreach(var type in types) { IMyServiceInterface instance = resolver.Get(type); instance.DoAction(); } }

Static members class vs. normal c-like interface

若如初见. 提交于 2019-11-27 07:52:12
问题 Hey there. After reading here about the Service Locator pattern, it got me thinking wether a class with only static members really is the way to go, or if a normal c-like interace wouldn't be more appropriate. I see people throwing around the class keyword all the time when they don't even need it. Example with static members class taken from the linked page: class Locator { public: static IAudio* GetAudio() { return service_; } static void Register(IAudio* service) { service_ = service; }

Is it bad to use servicelocation instead of constructor injection to avoid writing loads of factory classes

南楼画角 提交于 2019-11-27 05:48:25
问题 Right now we use DI/IOC and when we need to pass extra parameters to a constructor we use a factory class e.g. public class EmailSender { internal EmailSender(string toEmail, string subject,String body, ILogger emailLogger) {.....} } public class EmailSenderFactory { ILogger emailLogger; public EmailSenderFactory(ILogger emailLogger) { this.emailLogger = emailLogger; } public EmailSender Create(string toEmail, string subject, string body) { return new EmailSender(toEmail, subject, body,

Is IDependencyResolver an anti-pattern?

大城市里の小女人 提交于 2019-11-27 03:51:31
I am designing some architectural changes into a legacy ASP.NET application. I prototyped some classes for dependency resolution that mimic the ASP.NET MVC's IDependencyResolver. I won't post because it is pretty much the same interface, but in other natural language. I figured out it might be considered Service Location, which in turn is usually (not fully in some cases) condemned in favor of Dependency Injection. Nevertheless, I couldn't find any recommendation against the use of the ASP.NET MVC's dependency resolution implementation. Is the ASP.NET MVC's IDependencyResolver considered an

What is the difference between using the Service Locator anti-pattern and using the Castle Windsor container?" [closed]

▼魔方 西西 提交于 2019-11-27 02:58:18
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Recently, I have been trying to understand what is the difference between using the Service Locator "anti-pattern" and using the Castle Windsor container. I have found some info here and there on the Internet and I have summarized what I have learned so far in an unfinished blog

Is IDependencyResolver an anti-pattern?

◇◆丶佛笑我妖孽 提交于 2019-11-26 10:55:49
问题 I am designing some architectural changes into a legacy ASP.NET application. I prototyped some classes for dependency resolution that mimic the ASP.NET MVC\'s IDependencyResolver. I won\'t post because it is pretty much the same interface, but in other natural language. I figured out it might be considered Service Location, which in turn is usually (not fully in some cases) condemned in favor of Dependency Injection. Nevertheless, I couldn\'t find any recommendation against the use of the ASP

Dependency Injection vs Service Location

余生长醉 提交于 2019-11-26 08:02:09
问题 I am currently weighing up the advantages and disadvantages between DI and SL. However, I have found myself in the following catch 22 which implies that I should just use SL for everything, and only inject an IoC container into each class. DI Catch 22: Some dependencies, like Log4Net, simply do not suit DI. I call these meta-dependencies and feel they should be opaque to calling code. My justification being that if a simple class \'D\' was originally implemented without logging, and then