inversion-of-control

Abstracting IoC Container Behind a Singleton - Doing it wrong?

泄露秘密 提交于 2019-12-18 11:12:49
问题 Generally, I like to keep an application completely ignorant of the IoC container. However I have ran into problems where I needed to access it. To abstract away the pain I use a basic Singleton. Before you run for the hills or pull out the shotgun, let me go over my solution. Basically, the IoC singleton does absolutly nothing, it simply delegates to an internal interface that must be passed in. I've found this makes working with the Singleton less painful. Below is the IoC wrapper: public

What is AOP, Dependency Injection and Inversion Of Control in Simple English

和自甴很熟 提交于 2019-12-18 10:00:25
问题 I have tried to understand AOP, Dependency Injection and Inversion of Control SPRING related concepts but I am having hard time understanding it. Can anyone explain this in simple English ? 回答1: I understand your confusion and it took me some time to understand how these concepts were related together. So here is my (somehow personal) explanation of all this: 1. Inversion of Control Inversion of control is a design principle rather generic that refers to the decoupling of the specification of

Register component based on parameter name on requestor in windsor

半世苍凉 提交于 2019-12-18 08:39:28
问题 I have this interface for using AutoMapper: public interface IMapper { object Map(object source, Type sourceType, Type destinationType); } Then for each type of data, I have a different mapper class , for example: public class UserMapper : IMapper { static UserMapper() { Mapper.CreateMap<User, UserViewModel>(); Mapper.CreateMap<UserViewModel, User>(); } public object Map(object source, Type sourceType, Type destinationType) { return Mapper.Map(source, sourceType, destinationType); } } Then I

Using Castle.Windsor with Windows Forms Applications

最后都变了- 提交于 2019-12-18 07:07:17
问题 Up until this point, I have been learning IoC/DI with Castle.Windsor using ASP.NET MVC, but I have a side project that is being done in Windows Forms, and I was wondering if there is an effective way to use it for that. My problem is in the creation of forms, services, etc. In ASP.NET MVC, there is a sort of 'Activator' that does this under the hood, but this isn't the case in Windows Forms. I have to create a new Form like var form = new fclsMain(); , so a Form like .. class fclsMain :

How to implement an [GoF]-ish Abstract Factory Pattern using an IoC like Ninject

时光总嘲笑我的痴心妄想 提交于 2019-12-18 07:06:32
问题 Abstract When the design requires an "Abstract Factory Pattern" like stated by the [GoF] including several products and over some product families, then setting up an IoC can become a bit tricky. Especially when the specific factory implementations need to be dispatched by runtime parameters and shared among some subsequent components. Given the follwing API, i was trying to set up my IoC (Ninject in this case) to retrieve Configuration objects configured through a IConfigurationFactory . The

How to use Dependency Injection and not Service Locator

瘦欲@ 提交于 2019-12-18 07:02:32
问题 I am hearing people say you should not use Service Locator for your Dependency Injection. So how exactly do you inject the dependencies without relying on a service locator? I want to try out IoC containers, but don't want to land into an anti-pattern. Should you just set everything up so there is one place where all classes always have a dependency chain to the deepest classes? (if I/that makes sense at all) I isn't right to have all your code littered with dependencies on the IoC container

How to use Ninject Conventions extension without referencing Assembly (or Types within it)

痞子三分冷 提交于 2019-12-18 05:36:30
问题 Sorry in advance for the long question, it's long because I've been digging at this all day. The general problem: I have an ASP.Net MVC2 application with the following projects: MyApp.Web, MyApp.Services, MyApp.Data. We code to interfaces and utilize Ninject 2 for DI/IoC. However, I'm getting awfully tired of typing (and forgetting to type): Bind<ISomeService>.To<SomeService>; So, knowing about Ninject.Extensions.Convensions, I have attempted to use it to automatically scan and register

.net-core Dependency Injection

。_饼干妹妹 提交于 2019-12-18 03:44:10
问题 I have a Generic repository which I want to register for DI, it implements an interface IRepository. Normally I would create an instance of it like this: IRepository repo = new Repository<Order>(); However I am trying to get up to speed in .net 5 ahead of release and want to get this working with DI, I have resorted to the following : services.AddTransient<DAL.IRepository<Models.Order>, DAL.Repository<Models.Order>>(); But this feels wrong, I don't want 50+ lines in there one for each of the

Which .NET dependency injection framework do you use? [closed]

耗尽温柔 提交于 2019-12-18 03:43:18
问题 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 7 years ago . Currently there are quite a few DI/IoC-frameworks for .NET out there (http://www.hanselman.com/blog

What are “ForwardedTypes” in the context of Castle Windsor component registration?

自闭症网瘾萝莉.ら 提交于 2019-12-18 03:17:15
问题 As the subject says, really! What do they do? 回答1: Forwarded types allow you to have more than one service implemented by a single implementation, for a concrete example say we have two interfaces for working with tree nodes of some sort: public interface INodeAlterationProvider { ... } public interface IChildNodeListProvider { ... } And various components take a dependency on one or both of those interfaces. However in implementing each of those interfaces you discover that their is a lot of