inversion-of-control

Transform callbacks into a stream

此生再无相见时 提交于 2019-12-11 06:38:43
问题 In Perl, how can one transform a function that requires callbacks to a new function that returns a stream of results? Image I have a fixed function I can't change: sub my_fixed_handler { my $callback = shift; my $count = 1; while(1) { $callback->($count++); } } To print all the a count of numbers I could easily write this code: my_fixed_handler( sub { my $num = shift; print "...$num\n"; }); But now I need another function based on on the my_fixed_handler that will return only the result of

Dependency Injection with Cyclic Dependency

雨燕双飞 提交于 2019-12-11 06:25:18
问题 Let me have two very basic objects like: public class View { public View(Controller controller) { // Use the model exposed by the controller here } } public class Controller { private readonly IView view; public Controller() { this.view = new View(this); } public Controller(View v) { this.view = v; } } Later I decide to inject View object into the Controller via DI but there I have a cyclic dependency (i.e. I can't use var ctrl = new Controller(new View(ctrl)); ). How would you go about

Safely making wide-reaching change to IoC/DI config

五迷三道 提交于 2019-12-11 05:09:52
问题 Specific Question: How can I unit Test my DI configuration against my codebase to ensure that all the wiring up still works after I make some change to the automated binding detection. I've been contributing to a small-ish codebase (maybe ~10 pages? and 20-30 services/controllers) which uses Ninject for Ioc/DI. I've discovered that in the Ninject Kernel it is configured to BindDefaultInterface . That means that if you ask it for an IFoo, it will go looking for a Foo class. But it does that

IoC Register Instance Issue with MVC3, Unity & NHibernate - (Unity.MVC3 lib from codeplex)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 04:07:43
问题 I'm using the Unity.MVC3.dll from codeplex and am attempting to register an instance of a NHibernate ISession per request. As per the Unity MVC3 docs I should just have to use the HierarchicalLifetimeManager to accomplish this: var container = new UnityContainer(); container.RegisterInstance<ISession>(SessionFactory.OpenSession(), new HierarchicalLifetimeManager()); container.RegisterControllers(); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); SessionFactory is a

How to manage interface segregation when using an IoC container? [duplicate]

夙愿已清 提交于 2019-12-11 03:59:46
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a small system and i'm currently using structureMap as IoC. I just recently got the point of interface segregation...and I'm wondering now. If I have a certain business object, that will implement say, three interfaces... how should I handle this in the configuration and instatiation of code? Assuming I have two interfaces

IoC (spring.net) with asp.net - ctor injected non-singleton objects on controller - where do I dispose?

拟墨画扇 提交于 2019-12-11 03:46:13
问题 I'm using asp.net MVC 4 - I have spring.net setup to ctor inject objects on construction of my controllers, but some of the objects aren't singletons, so I'm unsure as to how to handle the dispose method on these objects once the controller is disposed. It just feels wrong calling these objects dispose methods in the controller class as the controller class didn't construct these objects, my IoC container did. Any help would be much appreciated. Thank you. 回答1: Consider defining Request scope

How to register a type with autofac after container creation

风流意气都作罢 提交于 2019-12-11 03:31:44
问题 I have an infrastructure singleton that I would like resolved out of autofac At container creation I register AppPaths as a singleton However, for a variety of reasons (testing, a few infrastructure things) I would like to be able to swap that instance out with a new one during runtime. Let's say a derived type class AppPaths2 : AppPaths . I can't find the API to do this. I can use CommentServiceLocator to get an instance of IComponentContext but I don't see a way to resolve stuff from there.

SPRING-WS No marshaller registered. Caused by SPRING IOC

…衆ロ難τιáo~ 提交于 2019-12-11 03:25:44
问题 I have a SOAP client service which works fine. The SOAP headers and request are managed in a SOAPConnector class . public class SOAPConnector extends WebServiceGatewaySupport { public Object callWebService(String url, Object request) { // CREDENTIALS and REQUEST SETTINGS... return getWebServiceTemplate().marshalSendAndReceive(url, request, new SetHeader(requestHeader)); } } I'm receiving the requested Data once I call my (SoapConnector) service on the main Class . @SpringBootApplication

Castle Windsor & Command Pattern

醉酒当歌 提交于 2019-12-11 03:17:40
问题 I am trying to implement a Command, CommandHandler and CommandDispatcher pattern using Castle Windsor without manually asking the container to resolve a CommandHandler based on Command type (which is generally considered an anti-pattern). I found this old article, but the implementation of ITypedFactoryComponentSelector has changed, so now it returns a Func, instead of TypedFactoryComponent . Anyway, I would really appreciate if someone can shed some light on the "correct" implementation of

Dependency Injection for Presenter

为君一笑 提交于 2019-12-11 03:03:59
问题 I have a Presenter that takes a Service and a View Contract as parameters in its constructor: public FooPresenter : IFooPresenter { private IFooView view; private readonly IFooService service; public FooPresenter(IFooView view, IFooService service) { this.view = view; this.service = service; } } I resolve my service with Autofac: private ContainerProvider BuildDependencies() { var builder = new ContainerBuilder(); builder.Register<FooService>().As<IFooService>().FactoryScoped(); return new