inversion-of-control

Dependency Injection and project structure for Console applications

被刻印的时光 ゝ 提交于 2019-12-04 10:53:09
问题 I have 4 projects: Core (IServer): System System.Core DependencyResolver: Core StructureMap Infrastructure (Service): Core External dependency Console: Core DependencyResolver Requierements: I am trying to use StructureMap only in the DependencyResolver. Furthermore the Console application should not know anything about Infrastucture. When I do not want to reference StructureMap on my Console Application I have to build a ServiceLocator. In the DependencyResolver I have a Bootstrapper that is

Simplest explanation of how a DI container works?

梦想与她 提交于 2019-12-04 10:28:59
问题 In simple terms and/or in high-level pseudo-code, how does a DI container work and how is it used? 回答1: At its core a DI Container creates objects based on mappings between interfaces and concrete types. This will allow you to request an abstract type from the container: IFoo f = container.Resolve<IFoo>(); This requires that you have previously configured the container to map from IFoo to a concrete class that implements IFoo (for example Foo). This in itself would not be particularly

How to reset all instances in IOC Container

时光毁灭记忆、已成空白 提交于 2019-12-04 09:52:51
I have made an C# WPF Application using the MVVM Light framework . My Application uses the ViewModelLocator class to locate the viewmodels during runtime. The ViewModelLocator makes usage of the SimpleIoc class which also comes with the MVVM Light framework . Here is my scenario: The user logs in an can use my application. On logout, i want to dispose/reset/recreate all viewmodel instances to provide a clean environment to the next user. I tried to implement the Cleanup() method in the ViewModelLocator class but it is not working. Not working means that the (second) user sees the data from the

What performance overhead do IoC containers involve?

不羁的心 提交于 2019-12-04 09:44:37
问题 Loose coupling is wonderful of course, but I have often wondered what overhead wiring up dynamically using an IoC container (for example Castle Windsor) has over a tightly coupled system? I know that a detailed answer would depend on what the IoC was being used for, but I'm really just trying to get a feel for the magnitude of effort involved in the IoC work. Does anyone have any stats or other resources regarding this? Thanks 回答1: There is links about performance http://realfiction.net/?q

MVC Integration tests with Unity IoC

对着背影说爱祢 提交于 2019-12-04 09:39:52
Am trying Unity IoC, after using constructor based DI. Problem is trying to get integration tests working. http://patrick.lioi.net/2013/06/20/streamlined-integration-tests/ "Running your integration tests should exercise as much of the real system as is reasonably possible" Patrick above describes setting up an IoC inside the MVC Unit test project.. but I'm stuck as to how to implement public class HomeController : Controller { readonly IWinterDb db; // Unity knows that if IWinterDb interface is asked for, it will inject in a new WinterDb() public HomeController(IWinterDb db) { this.db = db; }

Ninject - The resource cannot be found

不打扰是莪最后的温柔 提交于 2019-12-04 09:25:30
I get error The resource cannot be found. When I try to implement Ninject in my MVC-3 application. The problem appears to be coming from Global.asax during CreateKernel() #region Inversion of Control protected override IKernel CreateKernel() { return Container; } static IKernel _container; public static IKernel Container { get { if (_container == null) { _container = new StandardKernel(new SiteModule()); } return _container; } } internal class SiteModule : NinjectModule { public override void Load() { bool MOCKDB = true; //MOCKDB = false;//Stop Mocking if (MOCKDB) { //Set up mock bindings Bind

Using IOC in a remoting scenario

一曲冷凌霜 提交于 2019-12-04 09:18:19
I'm struggling with getting IOC to work in a remoting scenario. I have my application server set up to publish Services (SingleCall) which are configured via XML. This works just like this as we all know: RemotingConfiguration.Configure(ConfigFile, true); lets say my service looks like that (pseudocode) public class TourService : ITourService { IRepository _repository; public TourService() { _repository = new SqlServerRepository(); } } But what I rather would like to have sure looks like this: public class TourService : ITourService { IRepository _repository; public TourService(IRepository

Is Spring session scoped bean saved in HttpSession?

前提是你 提交于 2019-12-04 09:14:51
Since I don't have in depth knowledge of spring session scope implementation. Can anyone please tell me if it is wise to use Spring Session scoped beans, where HttpSession object is very crucial. Like a web application where thousands of users access the site simultaneously. Is spring session scoped bean saved in HttpSession object? Or even if HttpSession object only refers to the spring session scoped bean, are we not making session object heavy? How is it different form storing any bean directly in HttpSession object (making HttpSession object heavy point of view)? The object is not really

structuremap - two implementations of same interface

夙愿已清 提交于 2019-12-04 08:07:54
问题 I have a service class with the following ctor: public class (IMessageService emailService, IMessageService smsService) { ... } and two implementations of IMessageService (email and sms). How do I configure the container to resolve this constructor correctly? Is this where named instances come in, or is that for another scenario? 回答1: You could use named instances or smart instances to solve this... // Named instances this.For<IMessageService>().Use<EmailService>().Named("emailService"); this

Why would you want Dependency Injection without configuration?

孤人 提交于 2019-12-04 07:50:15
After reading the nice answers in this question , I watched the screencasts by Justin Etheredge. It all seems very nice, with a minimum of setup you get DI right from your code. Now the question that creeps up to me is: why would you want to use a DI framework that doesn't use configuration files? Isn't that the whole point of using a DI infrastructure so that you can alter the behaviour (the "strategy", so to speak) after building/releasing/whatever the code? Can anyone give me a good use case that validates using a non-configured DI like Ninject? I don't think you want a DI-framework without