dependency-injection

Property Injection into an Action Filter

﹥>﹥吖頭↗ 提交于 2019-12-22 06:27:34
问题 I'm trying to get Property Injection working on a Custom Action Filter Attribute. It is working as it is supposed to, however, I'd like to use DI on the Property itself. My filter looks like this [AttributeUsage(AttributeTargets.Class)] public sealed class HeaderFilterAttribute : ActionFilterAttribute { public IMarketService MarketService { get; set; } public override void OnActionExecuted(ActionExecutedContext filterContext) { var view = (ViewResultBase)filterContext.Result; if (view != null

When using dependency injection, where do all the new operators go?

江枫思渺然 提交于 2019-12-22 06:06:28
问题 I've been reading about dependency injection, and I understand the basic concept that a method should receive what it needs from its caller rather than creating such items itself. As a result, new operators get removed from the method almost entirely (certain basic objects would be exempt, of course - one example of this I found was for things like StringBuilder s which seem like they'd be insane to have to pass in). My question sounds deceptively simple, but I suspect the answer is actually

Decoupling the view, presentation and ASP.NET Web Forms

风格不统一 提交于 2019-12-22 05:59:21
问题 I have an ASP.NET Web Forms page which the presenter needs to populate with controls. This interaction is somewhat sensitive to the page-life cycle and I was wondering if there's a trick to it, that I don't know about. I wanna be practical about the whole thing but not compromise testability. Currently I have this: public interface ISomeContract { void InstantiateIn(System.Web.UI.Control container); } This contract has a dependency on System.Web.UI.Control and I need that to be able to do

Decoupling the view, presentation and ASP.NET Web Forms

家住魔仙堡 提交于 2019-12-22 05:59:11
问题 I have an ASP.NET Web Forms page which the presenter needs to populate with controls. This interaction is somewhat sensitive to the page-life cycle and I was wondering if there's a trick to it, that I don't know about. I wanna be practical about the whole thing but not compromise testability. Currently I have this: public interface ISomeContract { void InstantiateIn(System.Web.UI.Control container); } This contract has a dependency on System.Web.UI.Control and I need that to be able to do

Injecting dependencies to ServletContextListener with Guice

喜欢而已 提交于 2019-12-22 05:58:52
问题 Since ServletContextListener is created by the server, not by Guice I can't find a way to make it work together. How do I get guice injector at ServletContextListener? Maybe there is better way to shutdown services like logger or persistance then doing it at contextDestroyed method and initialize them at contextInitialized? 回答1: The extension GuiceServlet puts the injector in the servlet context, so you can get it by doing something like this: public class MyServletContextListener implements

How to inject dependencies into classes that implement an interface?

混江龙づ霸主 提交于 2019-12-22 05:51:53
问题 I know interfaces cannot define constructors. What is the best practice to force all classes implementing an interface, to receive their dependencies in a uniform contract. I know ints possible to inject dependencies into objects via properties, but passing them via constructors makes more sense to me. How to DI then ? 回答1: I know you said you want to have a stable contract. But an advantage to not supplying a stable interface is that your dependencies could then vary wildly with different

Does using annotations to inject dependencies remove the main benefit of dependency injection(external configuration)?

跟風遠走 提交于 2019-12-22 05:40:10
问题 I am using Spring, here is a controller: @Controller public class PersonController { @Resource(name="PersonService") private PersonService personService; @RequestMapping(value = "/Person", method = RequestMethod.GET) public String getPersons(Model model) { // Retrieve all persons by delegating the call to PersonService List<Person> persons = personService.getAll(); // Attach persons to the Model model.addAttribute("persons", persons); //then return to view jsp } and here is a service :

How do I inject a constructor dependency into a ViewModel using Xamarin and Autofac?

本秂侑毒 提交于 2019-12-22 05:26:07
问题 I have a ViewModel and I want to inject another Class into it. I am using Visual Studio with the latest version of Xamarin. I'm using Autofac for registering en resolving dependencies. But I'm new to it and I'm facing a problem which I can't find the solution to, even though it's probably simple. This is the Class in which I want to inject another Class: public IMessagingCenterWrapper MessagingCenterWrapper; public LoginViewModel(IMessagingCenterWrapper messagingCenterWrapper){

ASP.NET Web API Dependency Injection

白昼怎懂夜的黑 提交于 2019-12-22 05:24:21
问题 I would like to know if it is possible to do dependency injection (custom constructor) in a ASP.NET Web API without the use of third party libraries such as Unity or StructureMap and without Entity Framework. What I would like to achieve is have a controller with a constructor such as: public Controller(IDatabaseConnector connector) { ... } I know for MVC you can make a custom ControllerFactory by inheriting from DefaultControllerFactory and then overriding the GetControllerInstance function.

How do I get google guice to inject a custom logger, say a commons-logging or log4j logger

纵然是瞬间 提交于 2019-12-22 05:14:29
问题 Google guice has a built-in logger binding. But what if I want to use a commons-logging or log4j logger? Can I get guice to inject a Log created by LogFactory.getLog(CLASS.class) But having the same behavior as in built-in binding: The binding automatically sets the logger's name to the name of the class into which the Logger is being injected.. Does it even makes sense? Or shout I simply use the built-in java Logger? Or just use commons-logging without injections? 回答1: The CustomInjections