inversion-of-control

IoC setup and issue with inherited class

点点圈 提交于 2019-12-12 06:30:39
问题 I'm fairly new to the IoC pattern and I've hit an issue on the way the following should be setup. I've got a Service class which has the following constructor: public BookingService(IBookingRepository bookingRepository, IUnitRepository unitRepository, IRateRepository rateRepository, IDiscountRepository discountRepository, IUnitOfWork unitOfWork) { this.bookingRepository = bookingRepository; this.unitRepository = unitRepository; this.rateRepository = rateRepository; this.discountRepository =

Example of Dependency Injection with only base class

落爺英雄遲暮 提交于 2019-12-12 05:12:55
问题 Is it possible to do DI without any third party tools? I've read about people doing it with an abstract class and interface before they discovered some DI framework. How is ID done in that very basic form? 回答1: Just pass the dependencies to the constructor of the class when you instantiate it. No DI frameworks are needed when the project is small (below a couple of thousand lines of code) - you can write a factory and wire up all the dependencies manually. 回答2: Of course it's possible without

Inject functions with side-effects

ぃ、小莉子 提交于 2019-12-12 04:25:46
问题 I'm having an issue when using higher-order functions. Let's say I have the following code that doesn't use them (instead call global functions): import {db_insert} from 'some-db-lib' // function with side-effect const save_item = (item) => { // some logic like validating item data... db_insert(item) // call db_insert globally } const handle_request = (request) => { // some logic like sanitizing request... save_item(request.data) // call save_item globally } handle_request(some_request) And

Default constructor and open generics in MEF 2 using conventions

青春壹個敷衍的年華 提交于 2019-12-12 03:37:47
问题 I am trying to use MEF 2 in my project, I usually use SimpleInjector but this time I wanted to try MEF. My main problem is dealing with open generics, this is what i got so far public interface ISetting {} public class Setting : ISetting {} public interface ILogger<TLog> { TLog Fetch() } public class Logger<TLog> : ILogger<TLog> { private ISetting settings; public Logger(ISetting settings) { this.settings = settings; } public TLog Fetch() { return default(TLog); } } Now for the container part

Unity(3.5) Interception Not Working in MVC

旧城冷巷雨未停 提交于 2019-12-12 03:16:53
问题 I am trying to incorporate Interception using PolicyInjectionBehavior and get the this error: Exception information: Exception type: ResolutionFailedException Exception message: Resolution of the dependency failed, type = "CSR.Presentation.Controllers.HomeController", name = "(none)". Exception occurred while: Calling constructor Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior(Microsoft.Practices.Unity.InterceptionExtension.CurrentInterceptionRequest

Autofac Resolve using delegate factory by type

佐手、 提交于 2019-12-12 01:51:58
问题 I am using Autofac for IoC in my project. Due to some legacy software libraries I must pass some services to the controller that can't be resolved, and must be passed as parameter. I've made a generic control using delegate factories like this: public MyClass<TController, TInterface> { private delegate TController ControllerFactory(TInterface service); protected TController _myController; protected TController Controller { get { return _controller ?? (_controller = ServiceLocator.Resolve

spring settings repository

心不动则不痛 提交于 2019-12-12 00:29:38
问题 many of my application-properties are provided by the database i would like to inject them via a repository. I wonder if this is doable with spring. I would be happy if someone could suggest a solution. The code i'm thinking about looks something liek this: @Component public class ExampleService implements Service { private PlatformSetting setting1; @Required @Qualifier("setting1") public void setSetting1(PlatformSetting setting1) { this.setting1 = setting1; } public String getMessage() {

Spring Injected bean null when creating an object with new ,how to solve it?

纵饮孤独 提交于 2019-12-11 22:29:58
问题 I have an application , and now I am trying to use Spring to refactor it, and I have problem when creating object using new , but I don't know how to solve it. Here is the realtionship: I have a Controller , need a CommandService instance, and the CommandService need a RoomService to create AbstractRoom instances to put into RoomService instance's hashmap. I have two kinds of AbstractRoom called RoomA, RoomB, and they extend from AbstractRoom , and AbstractRoom needs GameService instance. I

Set constructor parameter type for structuremap Registry

家住魔仙堡 提交于 2019-12-11 19:59:38
问题 This is the follow up question to thread: How to pass parent/child class as constructor parameter with structuremap? Thanks PHeiberg. Really helps. Got another two questions: Why do we need PricingHandlerFactory constructor there? What it frustrate me is that actually PricingHandler is not invoked directly, we are using reflection and Registry to find PricingHandler. i.e.(Not all codes are pasted.) public class MessageHandlerRegistry : Registry { public MessageHandlerRegistry() { Scan(x => {

What is the current state of IoC containers in .NET? [closed]

三世轮回 提交于 2019-12-11 17:11:44
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I know similar questions have been asked before I'm looking to get the current state of IoC container framework in the .NET sphere.