service-locator

How to avoid service locator in .net extension methods

蹲街弑〆低调 提交于 2021-01-27 05:48:41
问题 I'm looking for a clean pattern to use dependencies in .Net extension methods without explicitly newing-up or using a service locator: public static class HttpContextExtensions { public static SomeClass ExtensionMethod(this HttpContext context) { //looking to avoid this var dependency = ServiceLocator.GetService<DependencyType>(); return dependency.DoSomething(context); } } Am I barking up the wrong tree here? Should I be looking for a more direct solution that passes context into a method? I

Provider vs. Get_it

送分小仙女□ 提交于 2021-01-20 19:00:31
问题 Searching for Dependency Injection solutions for Flutter, I found two awesome libraries: provider and get_it . As far as I can see, provider has more boilerplate, but it fits really nicely with Flutter, allowing Consumer to rebuild parts of the Widget tree onde an injected value change. get_it on the other hand is more straightforward, easier to use, and not dependant on Flutter, so can be used with any Dart code. Are there any more differences and limitations between them? I know this is

Using spinner as global service

时间秒杀一切 提交于 2020-01-17 11:15:23
问题 I am using the following spinner from the ng2-admin theme: import {Injectable} from '@angular/core'; @Injectable() export class BaThemeSpinner { private _selector:string = 'preloader'; private _element:HTMLElement; constructor() { this._element = document.getElementById(this._selector); } public show():void { this._element.style['display'] = 'block'; } public hide(delay:number = 0):void { setTimeout(() => { this._element.style['display'] = 'none'; }, delay); } } So for each component I have

Testing ServiceLocator using JUnit

不问归期 提交于 2020-01-16 16:59:04
问题 This is a follow up question to my previous question. I am trying to write test case for my ServiceLocator class but it gives me the following error: com/iplanet/ias/admin/common/ASException java.lang.NoClassDefFoundError: com/iplanet/ias/admin/common/ASException at java.lang.ClassLoader.defineClass1(Native Method) My test case: public void testServiceLocator () throws UivException, NamingException { DataSource ds = ServiceLocator.getInstance().getDataSource("jdbc/RSRC/my/mydb"); //I have not

Testing ServiceLocator using JUnit

隐身守侯 提交于 2020-01-16 16:58:08
问题 This is a follow up question to my previous question. I am trying to write test case for my ServiceLocator class but it gives me the following error: com/iplanet/ias/admin/common/ASException java.lang.NoClassDefFoundError: com/iplanet/ias/admin/common/ASException at java.lang.ClassLoader.defineClass1(Native Method) My test case: public void testServiceLocator () throws UivException, NamingException { DataSource ds = ServiceLocator.getInstance().getDataSource("jdbc/RSRC/my/mydb"); //I have not

ServiceLocator get instance by passing construction parameter

孤街浪徒 提交于 2020-01-03 15:34:17
问题 How can I get object instance with service locator with the constructor below. ProductCode is the constructor parameter used to initialize member properties. For all other constructor parameters, I have registered them using unity in the global.asax file. Basic way to get object instance if constructor parameters are reference type: var productSettingsRepo = ServiceLocator.Current.GetInstance<ProductSettingsRepository>(); public ProductSettingsRepository(ILogWriter logWriter,