service-locator

How to declare the Unity InjectionFactory in XML configuration

 ̄綄美尐妖づ 提交于 2019-12-19 06:17:29
问题 I'm in the process of moving our Unity configuration to the web.config file. I'm stuck on how to migrate the following code config to the xml format: var container = new UnityContainer(); container.RegisterType<IPrincipal>(new InjectionFactory(x=> HttpContext.Current.User)); return container; Here are the XML declartion: <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <alias alias="IRepository" type="Model.IRepository, Model" /> <alias alias="Repository" type="Data

Service Locator, Dependency Injection (and Container) and Inversion of Control

主宰稳场 提交于 2019-12-18 13:01:39
问题 I've been programming for some time but never got interested in knowing in theory what each concept means, I may be using a variety of programming concepts, but without knowing it. Service Locator : For me, refers to a record of shortcuts to speed up development by reducing the amount of code. One question is: may Locator refer to namespaces/classes only, or I can have a registry of variables? Here is my understanding of it: $locator = new ServiceLocator() $locator->set('app', new System

Why is MVC4 using the Service Locator Anti-Pattern?

不问归期 提交于 2019-12-18 10:15:22
问题 After reading "Dependency Injection in .NET" by Mark Seemann I stay away from the Service Locator which is an anti-pattern. Upon reading the release notes on MVC 4 I see: Improved Inversion of Control (IoC) via DependencyResolver: Web API now uses the service locator pattern implemented by MVC’s dependency resolver to obtain instances for many different facilities. Thus I'm left curious and confused why Microsoft would use a service locator in 2012. 回答1: That's an implementation detail that

How to use Dependency Injection and not Service Locator

瘦欲@ 提交于 2019-12-18 07:02:32
问题 I am hearing people say you should not use Service Locator for your Dependency Injection. So how exactly do you inject the dependencies without relying on a service locator? I want to try out IoC containers, but don't want to land into an anti-pattern. Should you just set everything up so there is one place where all classes always have a dependency chain to the deepest classes? (if I/that makes sense at all) I isn't right to have all your code littered with dependencies on the IoC container

Dependency Injection - use with Data Transfer Objects (DTOs)?

寵の児 提交于 2019-12-17 20:11:06
问题 Consider the code below (which has been simplified). I have a service class that returns a list of specific DTO objects that each implement their own specific interface. In the actual code these are getting populated by iterating thru a Dataset as I'm working with legacy code. Questions: How do we create/use a DTO without newing them up or using the Service Locator anti-pattern? It doesn't make much sense to compose an empty DTO object in the Composition Root and inject it into the Service

What's the difference between the Dependency Injection and Service Locator patterns?

試著忘記壹切 提交于 2019-12-16 22:34:42
问题 Both patterns seem like an implementation of the principle of inversion of control. That is, that an object should not know how to construct its dependencies. Dependency Injection (DI) seems to use a constructor or setter to "inject" it's dependencies. Example of using Constructor Injection: //Foo Needs an IBar public class Foo { private IBar bar; public Foo(IBar bar) { this.bar = bar; } //... } Service Locator seems to use a "container", which wires up its dependencies and gives foo it's bar

StructureMap resolve dependency through injection instead of service location

大城市里の小女人 提交于 2019-12-14 03:39:42
问题 In my project I register many ISerializers implementations with the assembly scanner. FWIW this is the code that registers my ISerializers Scan(scanner => { scanner.AssemblyContainingType<ISerializer>(); scanner.AddAllTypesOf<ISerializer>().NameBy(type => type.Name); scanner.WithDefaultConventions(); }); Which then correctly registers ISerializer (...ISerializer) Scoped as: Transient JsonSerializer Configured Instance of ...JsonSerializer BsonSerializer Configured Instance of ..

Cannot get text using text() in XPath

霸气de小男生 提交于 2019-12-13 04:08:35
问题 Here is part of html code: <td class="audit-context-break-word text-left" nowrap="nowrap"> <b class="ng-binding">PONumber</b></td> <td class="audit-context-break-word text-left ng-binding">20202022 02_001 </td> I need to get only text inside (expected value: 20202022 02_001) I tried following variants: By.xpath("/descendant::*[.='PONumber']/../descendant::*[@class=\"audit-context-break-word text-left ng-binding\"]/text()") By.xpath("/descendant::*[.='PONumber']/../following::text()[1]") The

SolrNet - The given key was not present in the dictionary

旧街凉风 提交于 2019-12-13 02:57:41
问题 I'm using SolrNet with vb.net 2.0 and can't seem to instantiate solr. Dim solr As ISolrOperations(Of PMWProperty) = ServiceLocator.Current.GetInstance(Of PMWProperty)() throws the exception: [KeyNotFoundException: The given key was not present in the dictionary.] System.ThrowHelper.ThrowKeyNotFoundException() +28 System.Collections.Generic.Dictionary`2.get_Item(TKey key) +7456108 SolrNet.Utils.Container.DoGetInstance(Type serviceType, String key) +22 Microsoft.Practices.ServiceLocation

zf2 ServiceManager vs ServiceLocator

蓝咒 提交于 2019-12-12 10:29:05
问题 I am learning zf2, reading docs, tutorials etc from the web. Now I am confused regarding Zend\ServiceManager\ServiceManagerAwareInterface.php and Zend\ServiceManager\ServiceLocatorAwareInterface.php . Also in some place (like controller) I use $this->getServiceLocator() to fetch the ServiceManager object while at some other places we use ->getServiceManager() and it also returns the same ServiceManager object. 回答1: The Locator is the interface. The design of Zend Framework 2 is done with