dependency-injection

PRISM + MEF — Import & ImportMany

这一生的挚爱 提交于 2021-01-27 06:15:09
问题 FooService.cs : public interface IFooService { int Foo(); } [Export("Foo1", typeof(IFooService))] public class Foo1 : IFooService { public int Foo() { return 1; } } [Export("Foo2", typeof(IFooService))] public class Foo2 : IFooService { public int Foo() { return 2; } } FooViewModel.cs : public class FooViewModel : NotificationObject { [ImportMany(typeof(IFooService))] public IEnumerable<IFooService> FooServices { get; private set; } [Import("Foo1")] public IFooService FirstFoo { get; private

Autofac property injection in base class

左心房为你撑大大i 提交于 2021-01-27 06:12:32
问题 I am working on a Windows Phone 8.1 application and I have a base class with public property. public class ViewModelBase { public ISomeClass MyProp {get;set;} } My derived class looks like this public class MainViewModel : ViewModelBase { private readonly INavigation _navigation; public MainViewModel(INavigation navigation) { _navigation = navigation; } } In my App.cs I have var builder = new ContainerBuilder(); builder.RegisterType<Navigation>().As<INavigation>(); builder.RegisterType

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

Guice Custom Injection for constructor parameters

社会主义新天地 提交于 2021-01-27 05:36:36
问题 I read about Custom Injection in Guice here: https://github.com/google/guice/wiki/CustomInjections This scheme describes how you can create a MembersInjector for injecting fields of a class. I am able to do this successfully. However, I do not like the idea of field injection and would like to do this to inject parameters of a constructor. Does anybody have a clue as to how this can be achieved for constructor injection? Specifically: public class PaymentService { private final Logger logger;

Cannot create a DbSet for 'Model' because this type is not included in the model for the context

假如想象 提交于 2021-01-27 04:51:34
问题 I do a Generic and using DI so I create a empty class public class DBRepo { } and my model class to inheriting class DBRepo public partial class UserAccount : DBRepo { public int Id { get; set; } public string Account { get; set; } public string Pwd { get; set; } } then this is a Interface to do CRUD public interface IDBAction<TEntity> where TEntity : class,new() { void UpdateData(TEntity _entity); void GetAllData(TEntity _entity); } public class DBService<TEntity> : IDBAction<TEntity> where

Inject service into Nhibernare Envers to customize revision entity

╄→尐↘猪︶ㄣ 提交于 2021-01-26 02:08:46
问题 I'am using NHibernate and envers in a .net 5 web application, i need to add user id to default revision entity and find no way to use dependency injection to do it. this is envers configuration private static void SetupEnvers(NHibernate.Cfg.Configuration cfg) { var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration(); enversConf.Audit<Persona>(); IRevisionListener revListner = new EnversRevisionListener(new IUserManagement); enversConf.SetRevisionEntity<RevisionEntity

Inject service into Nhibernare Envers to customize revision entity

左心房为你撑大大i 提交于 2021-01-26 02:07:44
问题 I'am using NHibernate and envers in a .net 5 web application, i need to add user id to default revision entity and find no way to use dependency injection to do it. this is envers configuration private static void SetupEnvers(NHibernate.Cfg.Configuration cfg) { var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration(); enversConf.Audit<Persona>(); IRevisionListener revListner = new EnversRevisionListener(new IUserManagement); enversConf.SetRevisionEntity<RevisionEntity

Inject service into Nhibernare Envers to customize revision entity

左心房为你撑大大i 提交于 2021-01-26 02:07:11
问题 I'am using NHibernate and envers in a .net 5 web application, i need to add user id to default revision entity and find no way to use dependency injection to do it. this is envers configuration private static void SetupEnvers(NHibernate.Cfg.Configuration cfg) { var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration(); enversConf.Audit<Persona>(); IRevisionListener revListner = new EnversRevisionListener(new IUserManagement); enversConf.SetRevisionEntity<RevisionEntity

Service instantiated twice after APP_INITIALIZER

送分小仙女□ 提交于 2021-01-23 06:22:13
问题 Problem is: I need to make an http call and store an object that is needed for generate dynamic routes. So, I was taking advantage of the APP_INITIALIZER. // app.module.ts import { ApplicationService } from './application.service'; providers: [ ApplicationService, { provide: APP_INITIALIZER, useFactory: appServiceFactory, deps: [Injector, ApplicationService], multi: true }, ], function appServiceFactory(injector: Injector, appService: ApplicationService): Function { return () => { return

Service instantiated twice after APP_INITIALIZER

亡梦爱人 提交于 2021-01-23 06:22:13
问题 Problem is: I need to make an http call and store an object that is needed for generate dynamic routes. So, I was taking advantage of the APP_INITIALIZER. // app.module.ts import { ApplicationService } from './application.service'; providers: [ ApplicationService, { provide: APP_INITIALIZER, useFactory: appServiceFactory, deps: [Injector, ApplicationService], multi: true }, ], function appServiceFactory(injector: Injector, appService: ApplicationService): Function { return () => { return