dependency-injection

How to use factory provider?

孤人 提交于 2019-12-21 03:56:11
问题 I need to inject a service into another service in an Angular 2 application. After reading the docs I deduced, that the best approach is to use a Factory Provider. However, two questions have arisen: 1) The docs recommend the creation of a HeroServiceProvider class with two "code segments": let heroServiceFactory = (logger: Logger, userService: UserService) => { return new HeroService(logger, userService.user.isAuthorized); }; export let heroServiceProvider = { provide: HeroService,

How do I get a reference to an IHostedService via Dependency Injection in ASP.NET Core?

荒凉一梦 提交于 2019-12-21 03:54:12
问题 Details I have attempted to create a background processing structure using the recommended IHostedService interface in ASP.NET 2.1. I register the services as follows: services.AddSingleton<AbstractProcessQueue<AbstractImportProcess>>(); services.AddHostedService<AbstractBackgroundProcessService<AbstractImportProcess>>(); services.AddSignalR(); The AbstractProcessQueue is just a wrapper around a BlockingCollection of processes that can be enqueued and dequeued. The

conditional component registration in autofac

霸气de小男生 提交于 2019-12-21 03:45:30
问题 Is it possible to register a component conditionally on an other component's state? Something like: ContainerBuilder.RegisterConditionally<T>( Func<IComponentContext, bool>, Func<IComponentContext, T>); I've found that prior to V2 of autofac one could use a " Register().OnlyIf() " construction that seemed like the one I'm looking for. I would like such feature to conditionally override a default registration. class CommonRegistrations { public virtual void Register(ContainderBuilder builder)

Override autofac registration with plugin

半世苍凉 提交于 2019-12-21 03:32:09
问题 I have an IFoo service implemented by DefaultFoo , and I've registered it as such in my autofac container. Now I would like to allow for an alternative implementation of IFoo to be implemented in a plugin assembly, which can be dropped in a "plugins" folder. How do I configure autofac to prefer this alternative implementation if it is present? 回答1: If you register some interface implementations, Autofac will use the latest registration. Other registrations will be overridden. In your case,

How do I work with Ninject in an ASP.NET MVC Web App?

强颜欢笑 提交于 2019-12-21 03:25:27
问题 I've created a new MVC Web application and I have references to Ninject.dll, Ninject.Web.Common.dll and Ninject.Web.MVC.dll. Global.asax.cs: public class MvcApplication : NinjectHttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", /

How to add dependency to Android Studio manually

烈酒焚心 提交于 2019-12-21 02:52:17
问题 I try several times to add dependency to my project and each time give error the dependency that I want to add them are 'de.hdodenhof:circleimageview:1.3.0' and 'com.github.bumptech.glide:glide:3.6.1' so I want to download these and add to my project manually is it possible and if Yes How? Here is my application's build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion '24.0.0 rc4' defaultConfig { applicationId "ir.esfandune.material"

How to add dependency to Android Studio manually

蹲街弑〆低调 提交于 2019-12-21 02:52:15
问题 I try several times to add dependency to my project and each time give error the dependency that I want to add them are 'de.hdodenhof:circleimageview:1.3.0' and 'com.github.bumptech.glide:glide:3.6.1' so I want to download these and add to my project manually is it possible and if Yes How? Here is my application's build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion '24.0.0 rc4' defaultConfig { applicationId "ir.esfandune.material"

Dispose of Injected HttpClient

北城以北 提交于 2019-12-21 02:44:11
问题 Our MVC application calls a WebAPI action using HttpClient. I decided to inject the HttpClient using StructureMap and override dispose in the controller public HomeController(HttpClient httpClient) { _httpClient = httpClient; } protected override void Dispose(bool disposing) { if (disposing && _httpClient != null) { _httpClient.Dispose(); } base.Dispose(disposing); } The StructureMap ObjectInitialize basically looks like this.. x.For<HttpClient>().Use(() => new HttpClient() { BaseAddress =

injecting viewmodel class without parameterless constructor in WPF with NInject

混江龙づ霸主 提交于 2019-12-21 02:41:10
问题 I'm using NInject to resolve the dependency for my first WPF application. Following are my code snippets. My App.xaml.cs goes like. public partial class App : Application { private IKernel container; protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); ConfigureContainer(); ComposeObjects(); } private void ComposeObjects() { Current.MainWindow = this.container.Get<MainWindow>(); } private void ConfigureContainer() { this.container = new StandardKernel(); container.Bind

Using an existing IoC Container in SignalR 2.0

眉间皱痕 提交于 2019-12-21 02:22:12
问题 How can I use an existing IoC with SignalR 2.0? From the tutorial, it seems I need to setup a class to be called from OWIN via an attribute: using Microsoft.Owin; using Owin; [assembly: OwinStartup(typeof(SignalRChat.Startup))] namespace SignalRChat { public class Startup { public void Configuration(IAppBuilder app /*HOW AM I GONNA GET UNITY CONTAINER HERE?*/) { var hubConfig = new HubConfiguration() { EnableJSONP = true, EnableDetailedErrors = true, EnableJavaScriptProxies = true, Resolver =