dependency-injection

Custom Role Provider using DI ninject throwing error

百般思念 提交于 2019-12-20 00:20:10
问题 I setup a CustomRoleProver as: public class CustomRoleProvider : RoleProvider { private readonly IRepository<User> _repository; public CustomRoleProvider(IRepository<User> repository) { _repository = repository; } ... In my Global.asax.cs I have: //Create Ninject DI kernel var kernel = new StandardKernel(); kernel.Bind<IRepository<User>>().To<Repository<User>>(); //Tell ASP.NET MVC 3 to use our Ninject DI Container DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); When I

Where is the composition root in a WPF MDI application?

佐手、 提交于 2019-12-19 21:47:26
问题 In traditional MDI applications some objects (Forms) will be created when a command occurs (Ex. pressing a ribbon button), so it maybe a composition point. I'm confiused about composition root in such applications. I read somewhere that we can use a ViewModelLocator which looks like Service Locator pattern. As you know the service locator pattern is denounced by some people. Now please advice me about this issue. Thanks in advance. 回答1: Whether or not a ViewModelLocator is a Service Locator

Injected objects became null after upgrading to Roboguice 3

大城市里の小女人 提交于 2019-12-19 19:52:53
问题 I've just upgraded our project to use Roboguice 3 and all of a sudden all the injected objects became null, that includes POJO, Providers, Views, Resources etc. And I'm struggling to figure out why. First of all there's the gradle build file, tried both Proguard on and off and it didn't make a difference. I believe we are currently using Roboguice 3.0.1, but I tried 3.0 and still had the problem. compile ('org.roboguice:roboguice:3.+') { exclude module: 'asm' } provided 'org.roboguice

StructureMap: Choose concrete type of nested dependency

試著忘記壹切 提交于 2019-12-19 19:51:31
问题 Calculators: public interface ICalculator { int Calculate(int a, int b); } public class Calculator : ICalculator { private readonly ICalculatorStrategy _calculatorStrategy; public Calculator(ICalculatorStrategy calculatorStrategy) { _calculatorStrategy = calculatorStrategy; } public int Calculate(int a, int b) { return _calculatorStrategy.Calculate(a, b); } } Calculator stragies: public interface ICalculatorStrategy { int Calculate(int a, int b); } public class AdditionCalculator :

Constructor injection vs Field injection

好久不见. 提交于 2019-12-19 15:14:10
问题 When injecting any services, I have two choices : (Field injection) @Inject private MyService myService; or ( Constructor injection ) private MyService myService; @Inject public ClassWhereIWantToInject(MyService mySerivce){ this.myService = myService; } Why Constructor injection is better than Filed injection ? 回答1: Do something like (I assume you are using spring-boot or something comparable for your CDI) public class ClassWhereIWantToInject{ private MyService myService; @Inject public

SignalR : How to use IHubContext<THub,T> Interface in ASP.NET MVC?

ぐ巨炮叔叔 提交于 2019-12-19 11:46:10
问题 I have been trying to used the following approach in my ASP.NET MVC project where Microsoft.AspNet.SignalR library is used: public interface ITypedHubClient { Task BroadcastMessage(string name, string message); } Inherit from Hub: public class ChatHub : Hub<ITypedHubClient> { public void Send(string name, string message) { Clients.All.BroadcastMessage(name, message); } } Inject your the typed hubcontext into your controller, and work with it: public class DemoController : Controller {

Dependency Injection using Template 10

烂漫一生 提交于 2019-12-19 11:37:14
问题 I am trying to migrate some code from an old Windows 8.1 app that I had developed using Prism/Unity to a new UWP app using Template 10 and Unity. I have seen in the documentation for Template 10 here that you can override the ResolveForPage method. In my old Windows 8.1 app, there is a Resolve method in Prism that I would override like this: protected override object Resolve(Type type) { return Container.Resolve(type); } The signature for the Template 10 method is public override INavigable

C# ASP.NET Dependency Injection with IoC Container Complications

你。 提交于 2019-12-19 11:35:19
问题 I apologise for the length, and I know there are some answers on this but I searched a lot and haven't found the right solution, so please bear with me. I am trying to create a framework for legacy applications to use DI in ASP.NET webforms. I will probably use Castle Windsor as the framework. These legacy applications will use in part an MVP pattern in some places. A presenter would look something like this: class Presenter1 { public Presenter1(IView1 view, IRepository<User> userRepository)

C# ASP.NET Dependency Injection with IoC Container Complications

这一生的挚爱 提交于 2019-12-19 11:35:08
问题 I apologise for the length, and I know there are some answers on this but I searched a lot and haven't found the right solution, so please bear with me. I am trying to create a framework for legacy applications to use DI in ASP.NET webforms. I will probably use Castle Windsor as the framework. These legacy applications will use in part an MVP pattern in some places. A presenter would look something like this: class Presenter1 { public Presenter1(IView1 view, IRepository<User> userRepository)

Searching for an elegant way in PHP for loading dependencies/services/configuration?

主宰稳场 提交于 2019-12-19 10:17:53
问题 I'm building a MVC PHP framework and I wonder which are the best practices to load what I need in my classes, be it other classes or plain configuration. Till today I've used singletons, registry and lately a dependency injection container. While many people claim that DI is the way to go, it seems to me like it justs moves the problem of coupling between components into another place. Singletons introduce global state, registry introduces tight coupling and DI introduces... well, lots of