inversion-of-control

How to resolve type at run time to avoid multipe if else

依然范特西╮ 提交于 2019-12-07 02:59:10
问题 I have my code which makes a webservice Call based on type of request. To do that , I have following code; public class Client { IRequest request; public Client(string requestType) { request = new EnrolmentRequest(); if (requestType == "Enrol") { request.DoEnrolment(); } else if (requestType == "ReEnrol") { request.DoReEnrolment(); } else if (requestType == "DeleteEnrolment") { request.DeleteEnrolment(); } else if (requestType == "UpdateEnrolment") { request.UpdateEnrolment(); } } } So as per

Best IoC framework for .Net [duplicate]

你。 提交于 2019-12-07 02:49:26
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Which .NET Dependency Injection frameworks are worth looking into? Which is the best IoC among StructureMap and Ninject? This should be merged with: Best injections frameworks 回答1: Depends on the situation. For small projects where you need a simple container I'd choose Ninject. I like the fact that it's small and lean. I dislike the attribute's but there are ways around that. For a big solution where you might

How to create a Ninject custom scope that returns the same object until that object is disposed?

霸气de小男生 提交于 2019-12-07 02:49:08
问题 In Ninject, declaring a binding in singleton scope means that the same object will be returned every time. There can only be one object, ever. What I would like is to return one object at a time. In other words: The first call to Get() instantiates a new object and returns it. Subsequent calls to Get() return the same instance. The object is disposed. The first call to Get() after the object was disposed instantiates a new/second object and returns that. Subsequent calls to Get() return the

IoC Castle Windsor - No parameterless constructor defined for this object

百般思念 提交于 2019-12-07 02:48:48
问题 I'm getting the 'No parameterless constructor defined for this object' on my controller when the controller and its dependencies are being registered accordingly via (DI/IoC) pattern using Castle Windsor. Can someone take a look at the following and see my error because i can't see it. Code for registration on global.asax public class MyApplication : System.Web.HttpApplication { public MvcApplication() { this.container = new WindsorContainer().Install(new DependencyInstaller()); } protected

How do I configure a single component instance providing multiple services in Castle.Windsor?

谁都会走 提交于 2019-12-07 02:32:24
问题 I'd like to configure the Windsor container so that a single, singleton-style instance can provide two or more services through the container. I've found that using the same type in multiple component declarations (XML-based config) will result in an instance of that type being created to provide each component's service interface, which is not the behaviour I desire. For example: interface IA { } interface IB { } class AB : IA, IB { ... } I want the one instance of AB to provide both the IA

Manually implementing IoC with a Windows Service

此生再无相见时 提交于 2019-12-07 02:17:02
问题 I am brand new to IoC and thus have been following the examples provided by Jeffery Palermo in his posts at http://jeffreypalermo.com/blog/the-onion-architecture-part-1/ and in his book hosted here https://github.com/jeffreypalermo/mvc2inaction/tree/master/manuscript/Chapter23 Most important to note is that I am not using a pre-rolled IoC container, mostly because I want to understand all the moving parts. However, I am creating a windows service rather than an ASP.NET MVC webapp so I am

How to inject an asynchronous dependency in inversify?

心不动则不痛 提交于 2019-12-07 01:37:12
问题 I have TypeScript application and I'm using Inversify for IoC. I have a connection class: 'use strict'; import { injectable } from 'inversify'; import { createConnection, Connection } from "typeorm"; import { Photo, PhotoMetadata, Author, Album } from '../index'; @injectable() class DBConnectionManager { public createPGConnection(): Promise<Connection> { return createConnection({ driver: { type: "postgres", host: "host", port: 5432, username: "username", password: "password", database:

MVC3, Ninject, MvcSiteMapProvider - How to inject dependency to overridden method

孤街醉人 提交于 2019-12-07 00:08:13
问题 I have an MVC3 application that is using Ninject and MvcSiteMapProvider. I have created this class which MvcSiteMapProvider uses to dynamically add nodes to my sitemap: public class PageNodeProvider : DynamicNodeProviderBase { public override IEnumerable<DynamicNode> GetDynamicNodeCollection() { // need to get repository instance var repository = // how do I get this??? foreach (var item in repository.GetItems()) { yield return MakeDynamicNode(item); } } } The MvcSiteMapProvider instantiates

Restlet server resource with constructor parameters needed

寵の児 提交于 2019-12-06 19:50:24
问题 Getting this error in restlet: ForwardUIApplication ; Exception while instantiating the target server resource. java.lang.InstantiationException: me.unroll.forwardui.server.ForwardUIServer$UnsubscribeForwardUIResource And I know exactly why. It's because my constructor looks like this: public UnsubscribeForwardUIResource(MySQLConnectionPool connectionPool) { And Restlet accesses the resource like so: router.attach(Config.unsubscribeUriPattern(), UnsubscribeForwardUIResource.class); Problem is

UnitOfWork in Action Filter seems to be caching

我的梦境 提交于 2019-12-06 18:53:31
问题 I have an MVC 3 site that uses IoC (Unity), and my model is generated w/ EF4 and POCOs. I am using an action filter to commit my UnitOfWork: public class UseUnitOfWorkAttribute : ActionFilterAttribute, IActionFilter { private readonly IUnitOfWork _unitOfWork; public UseUnitOfWorkAttribute() { _unitOfWork = IoCFactory.Instance.CurrentContainer.Resolve<IUnitOfWork>(); } void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) { _unitOfWork.Commit(); } void IActionFilter