service-locator

ServiceLocator.Current.GetInstance causes excessive number of calls to ObjectBuilder2.PolicyList.GetNoDefault

为君一笑 提交于 2019-12-11 19:21:48
问题 In my MVC4, .NET4.5 web app using Unity IoC container, in the method IoCContainerFactory.GetControllerInstance() we use ServiceLocator.Current.GetInstance to get the controller instance: public class IoCControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance( System.Web.Routing.RequestContext requestContext, Type controllerType) { // snip other code // this is the problem line: return ServiceLocator.Current.GetInstance(controllerType) as IController

How to Inject Helper Dependencies in Domain Model Entity Classes

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:37:49
问题 So I'm well underway in my effort to convert my desktop/WPF solution from using Service Locator pattern to using Dependency Injection. So far it has been relatively painless (since the same UnityContainer is used in both cases): I just remove each call to my global/static ServiceLocator and put the dependency in the constructor. But I'm stumped when it comes to a helper service that exists in one of my entity classes. Currently I have something like this: A singleton helper service which

Is the StaticFactory<T> in codecampserver a well known pattern?

妖精的绣舞 提交于 2019-12-10 18:01:43
问题 CodeCampServer source code contains a generic StaticFactory. I'm surmising that this is a key piece of the mechanism for how the framework plays well with Dependency Injection. Subclasses of which use it's DefaultUnconfiguredState to provide static access to, well, a Default Unconfigured State for themselves which the dependency resolution mechanism can replace with working stuff. I've not been able to find any documentation for this... Is there a good explanation in the book? (I'm awaiting

Implementing a Service Locator with injected variations of Generic Type

馋奶兔 提交于 2019-12-10 17:36:06
问题 I have the following: public interface IConverter<TValue, TConverted> { } public interface IConverterProvider { IConverter<TValue, TConverted> GetConverter<TValue, TConverted>(); } With an example binding at setup: Bind<IConverter<System.Int32, System.String>>().To<Int32ToStringConverter>(); Bind<IConverter<System.Guid, System.String>>().To<GuidToStringConverter>(); So I have a collection of fixed converters and no duplicate bindings. [Question] My question is how do I go about implementing

J2EE/EJB + service locator: is it safe to cache EJB Home lookup result?

落爺英雄遲暮 提交于 2019-12-10 15:42:52
问题 In a J2EE application, we are using EJB2 in weblogic. To avoid losing time building the initial context and looking up EJB Home interface, I'm considering the Service Locator Pattern. But after a few search on the web I found that even if this pattern is often recommended for the InitialContext caching, there are some negative opinion about the EJB Home caching. Questions: Is it safe to cache EJB Home lookup result ? What will happen if one my cluster node is no more working ? What will

LightInject IoC container throws stackoverflow when resolving type

北城以北 提交于 2019-12-10 13:45:36
问题 When trying out the LightInject IoC container http://www.lightinject.net/ it throws a stackoverflow exception when resolving the type ISomeService: All types are registered in App_Start: container.RegisterAssembly("MyApp*.dll"); And then when I try to resolve it in the controller it fails and throws a stackoverflow exception: public SomeController(ISomeService someService) { _someService = someService; } It also has the same error when using ServiceLocator: ServiceLocator.Current.GetInstance

injecting ServiceLocator via ServiceLocatorAwareInterface doesnt work

不问归期 提交于 2019-12-10 10:25:05
问题 i read that implementing: ServiceLocatorAwareInterface will inject the serviceLocator to the same class. So I got this: Class MyModel implements ServiceLocatorAwareInterface { protected $serviceLocator; public function setServiceLocator(ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; } public function getServiceLocator() { return $this->serviceLocator; } } But $this->serviceLocator is always NULL Do i have to do more than that? 回答1: You have to register

Resolving a class with a custom parameter in Simple Injector

与世无争的帅哥 提交于 2019-12-10 10:22:41
问题 I'm creating a WPF MVVM application using Simple Injector as DI container. Now I'm having some issues when I'm trying to resolve a view from Simple Injector, because I'm in need of passing a parameter into my constructor at construction time (not when registering the view to the container, thus this is not applicable: Simple Injector pass values into constructor). What I'm after is something like this: var item = container.GetInstance<MyType>(myParameter); I've read several places that this

How can I decouple my application from my membership service?

限于喜欢 提交于 2019-12-08 03:36:47
问题 I'm working on an ASP.NET MVC 4 project that uses Castle Windsor. One of the controllers has a dependency on MembershipService: public class FooController : Controller { private readonly MembershipService MembershipService; public FooController( MembershipService membershipService ) { MembershipService = membershipService; } [Authorize( Roles = "Administrator" )] public ActionResult DoSomething() { var user = MembershipService.GetUser( User.Identity.Name ); // etc... } } When I started

Access config global in Zend Framework 2

南楼画角 提交于 2019-12-08 02:01:14
问题 I would like to access to my global configs ( config/{,*.}{global,local}.php ) located in my personal libraries (in the vendor directory). But despite my search in the web, I did not succeed to achieve this. I know how to access the config file of a module : \MyModule\Module::getConfig() I know how to access the global configurations from a controller : $this->getServiceLocator()->get('config'); But how to access these from a file inside the vendor directory ? My libraries do not extend