dependency-injection

Configuring Unity to resolve a type that takes a decorated dependency that has a parameter that varies with the type into which it is injected

我的梦境 提交于 2019-12-31 21:30:31
问题 This is a fairly straight forward decorator pattern scenario, with the complication that the decorated type has a constructor parameter that is dependent on the type into which it is being injected. I have an interface like this: interface IThing { void Do(); } And an implementation like this: class RealThing : IThing { public RealThing(string configuration) { ... implementation ... } public void Do() { ... implementation ... } } And a decorator like this: class DecoratingThing : IThing {

IDisposable on an injected repository

大城市里の小女人 提交于 2019-12-31 16:40:17
问题 I have the following ADO .Net Repository public class Repository : IRepository, IDisposable { private readonly IUnitOfWork UnitOfWork; private SqlConnection Connection; public Repository(IUnitOfWork unitOfWork, connectionString) { UnitOfWork = unitOfWork; Connection = new SqlConnection(connectionString); Connection.Open(); } public MyObject FindBy(string userName) { //...Ado .Net command.ExecuteReader, etc. } } This repository is injected with an IoC container to a Domain Service and is used

Get the container instance for Simple Injector

廉价感情. 提交于 2019-12-31 12:35:14
问题 I am using Simple Injector with a ASP.NET MVC project. I added the SimpleInjector.Integration.Web.Mvc nuget package. This adds SimpleInjectorInitializer class in App_Start folder and initializes the DI. The code looks something like public static void Initialize() { // Did you know the container can diagnose your configuration? // Go to: https://simpleinjector.org/diagnostics var container = new Container(); //Container configuration code DependencyResolver.SetResolver( new

Test pipe with dependencies on services

落花浮王杯 提交于 2019-12-31 10:44:14
问题 I have a pipe that sanatises HTML as below: import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; @Pipe({ name: 'sanitiseHtml' }) export class SanitiseHtmlPipe implements PipeTransform { constructor(private _sanitizer: DomSanitizer) {} transform(value: any): any { return this._sanitizer.bypassSecurityTrustHtml(value); } } I want to test it as below: describe('Pipe: Sanatiser', () => { let pipe: SanitiseHtmlPipe; beforeEach(() => { pipe

dependency injection alternatives

冷暖自知 提交于 2019-12-31 10:41:15
问题 I am looking at depency injection, I can see the benefits but I am having problems with the syntax it creates. I have this example public class BusinessProducts { IDataContext _dx; BusinessProducts(IDataContext dx) { _dx = dx; } public List<Product> GetProducts() { return dx.GetProducts(); } } The problem is that I don't want to write BusinessProducts bp = new BusinessProducts(dataContextImplementation); I would continue to write BusinessProducts bp = new BusinessProducts(); because I feel

How to show Dependency Injection on a UML class diagram?

只谈情不闲聊 提交于 2019-12-31 10:31:25
问题 How do I show Dependency Injection of an object or class in a UML class diagram? 回答1: Martin Fowler shows it like this: 回答2: You display class dependencies by using a dashed line with a pointed arrow that points from the client model element to the supplier model element. I think that how you provide the dependencies to the client is irrelevent at the UML level. 来源: https://stackoverflow.com/questions/4488481/how-to-show-dependency-injection-on-a-uml-class-diagram

How to show Dependency Injection on a UML class diagram?

蓝咒 提交于 2019-12-31 10:31:12
问题 How do I show Dependency Injection of an object or class in a UML class diagram? 回答1: Martin Fowler shows it like this: 回答2: You display class dependencies by using a dashed line with a pointed arrow that points from the client model element to the supplier model element. I think that how you provide the dependencies to the client is irrelevent at the UML level. 来源: https://stackoverflow.com/questions/4488481/how-to-show-dependency-injection-on-a-uml-class-diagram

How to create dependency injection for ASP.NET MVC 5?

浪尽此生 提交于 2019-12-31 08:32:57
问题 Creating Dependency Injection with ASP.NET Core is fairly easy. The documentation explains it very well here and this guy has a killer video to explain it. However, I want to do the same thing with my ASP.NET MVC 5 project. How can handle dependency injection with ASP.MVC 5? Also, is Dependency injection limited to controllers only or can it work with any class? 回答1: In ASP.Net MVC you can use the .Net Core DI from NuGet rather than one of the third-party alternatives:- using Microsoft

How to create dependency injection for ASP.NET MVC 5?

时光毁灭记忆、已成空白 提交于 2019-12-31 08:32:57
问题 Creating Dependency Injection with ASP.NET Core is fairly easy. The documentation explains it very well here and this guy has a killer video to explain it. However, I want to do the same thing with my ASP.NET MVC 5 project. How can handle dependency injection with ASP.MVC 5? Also, is Dependency injection limited to controllers only or can it work with any class? 回答1: In ASP.Net MVC you can use the .Net Core DI from NuGet rather than one of the third-party alternatives:- using Microsoft

How to create dependency injection for ASP.NET MVC 5?

柔情痞子 提交于 2019-12-31 08:32:51
问题 Creating Dependency Injection with ASP.NET Core is fairly easy. The documentation explains it very well here and this guy has a killer video to explain it. However, I want to do the same thing with my ASP.NET MVC 5 project. How can handle dependency injection with ASP.MVC 5? Also, is Dependency injection limited to controllers only or can it work with any class? 回答1: In ASP.Net MVC you can use the .Net Core DI from NuGet rather than one of the third-party alternatives:- using Microsoft