inversion-of-control

Spring MVC 3.0 - Service layer using annonations

萝らか妹 提交于 2019-12-13 02:13:28
问题 In my Spring MVC application with a single Controller class, @Controller public class MyController { @RequestMapping(method = RequestMethod.POST, value = "/*.htm") public myMethod{@RequestBody final MyRequestBean myRequest} } My input is in the form of JSON and I use Jackson for converting it to Java object. Now, based on the property in the Java object, I want to send to appropriate service class. If it is, myRequest.value == "1" -> FirstService myRequest.value == "2" -> SecondService All

Single App consuming multiple IoC registries and has conflicts

筅森魡賤 提交于 2019-12-13 01:42:40
问题 I have a single application that talks to separate databases through two individual UnitOfWork classes. I am using StructureMap to build my classes. Individually, each one builds and runs correctly. However, once I consume both container registries within my " Web Application ", I get conflicts. Both registries reference the same DbContext (base) class from their common framework. However, each registry has its own concrete DbContext class (that inherits from DbContext ). The problem is...

how to init guice if my running class is junit?

感情迁移 提交于 2019-12-13 01:25:26
问题 I'm writing an API module. while developing I use junit to run the code however eventually some other modules will use my API. I want to use dependency injection pattern a) Where should be my main entry where I init all the dependencies or global utils? b) I thought it be neater using guice injector, but where should I init it? 回答1: It depends on what you're trying to do. I find, with BoundFieldModule and the @Bind annotation in Guice 4.0, that it's generally easiest to just use Guice

MVVM Light - Simple IoC + CommonServiceLocator? Trying to understand the purpose

守給你的承諾、 提交于 2019-12-13 01:24:05
问题 So I am aware that the CommonServiceLocator is an intermediary tie for allowing you to switch out different IoC containers, but looking at the MVVM Light's sample code, specifically the ViewModelLocator, it seems interesting in the sense that You register the SimpleIoC as the default locator, but at the same time you call Register on the SimpleIoc default instance. So if you were going to tear out SimpleIoC in the future, wouldn't it mean you'll need to update all the registration calls?

When is the Unity InjectionConstructor acually run?

混江龙づ霸主 提交于 2019-12-13 01:13:33
问题 I have the following code: IOC.Container.RegisterType<IRepository, GenericRepository> ("Customers", new InjectionConstructor(new CustomerEntities())); What I am wondering is if the new CustomerEntities() will be called once when the type registration happens OR if every time IRepository (with name "Customers") is resolved a new CustomerEntities will be made. If it is not the latter, then is there a way to make it work more like a delegate? (So it will make a new one every time it Resolves?) I

Unable to resolve AutoFac Keyed service with KeyFilterAttribute not working

自闭症网瘾萝莉.ら 提交于 2019-12-13 00:23:58
问题 I have a generic UnitOfWork pattern implementation and these UnitOfWork objects are dependencies to my service classes. Below snippets should help the reader understand my code setup: IUnitOfWork interface public interface IUnitOfWork<out TContext> where TContext : IDbContext UnitOfWork class public sealed class UnitOfWork<TContext> : IDisposable, IUnitOfWork<IDbContext> where TContext : IDbContext { private static readonly ILog Log = LogManager.GetLogger(typeof(UnitOfWork<TContext>));

How can I pass objects to ViewModels using NavigationService?

三世轮回 提交于 2019-12-12 17:51:24
问题 The project I am working on is a desktop based WPF application. I have implemented the MVVM pattern in it. Also I am using Unity IoC and the Repository Pattern in it. I have a problem in a master details type scenario. I navigate to the details Page(I have used IoC to expose the NavigationService in the ViewModel) but I dont know how can I get the employeeID in the EmployeeDetails ViewModel without breaking the MVVM pattern. I don't want to write anything in code behind. Any pointers will be

Allow calling function to override default options - jQuery UI dialog

久未见 提交于 2019-12-12 17:27:00
问题 I want the callingFunction to be able to override the default options provided in the showDivPopUp function. function calling(){ showDivPopUp("title of pop up box", "message to show", { buttons:{ Yes: function () { $(this).dialog("destroy"); }, No :function () { $(this).dialog("destroy"); } } }); } function showDivPopUp(title,msg,options){ var mgDiv = $("#msgDiv"); mgDiv.attr("innerHTML", msg); return mgDiv.dialog({ modal: true, buttons: { Ok: function () { $(this).dialog("destroy"); } },

Adding Dependency Injection to an MVVM application

淺唱寂寞╮ 提交于 2019-12-12 14:29:07
问题 Trying to backfill a WPF application using the MVVM pattern to work with dependency injection. I'm not overly familiar with DI, having worked with it only once before, but I think I understand the principles involved. I need to ensure that the bindings are all registered in one place - the application root. In WPF, this is the OnStartup method. So, I grabbed Ninject and threw it into my application to try and automatically bind my repository class to the initial view: private void OnStartup

How to inject IEnumerable using Microsoft Unity IOC container

纵饮孤独 提交于 2019-12-12 13:28:29
问题 I have a Service that need inject more than one provider, see below for example. How to use Unity to implement this feature? public class MyService: IMyService { public MyService(IEnumerable<Provider> Providers); } 回答1: I know this is an old question, but maybe this will help someone else that stumbles upon this. As long as you register the implementations with a specific name, this is possible to easily inject. You will then get all registered implementations. public class MyService: