inversion-of-control

configuration settings and IoC

蹲街弑〆低调 提交于 2019-12-22 14:49:01
问题 I use IoC (DI) approach and usually have parameters, which are being read from configuration settings (i.e. connection strings, static values etc) by the lowest layer (DB layer etc). What is the best way to do it? Read directly in this the lowest layer, i.e.: string sendGridApiKey = ConfigurationManager.AppSettings["SendGridApiKey"]; It works, but need to add also this key to config file of unit test project. Also, assembly depends on configuration file Read it in the highest layer (i.e. web

Enumerating disposables tracked by an Autofac lifetime

故事扮演 提交于 2019-12-22 13:52:40
问题 Autofac uses lifetime scopes as a way of disposing of all of the components created during a unit of work. While this is a powerful feature, it is easy to write code that doesn't dispose the lifetime scopes properly, which results in the number of tracked disposables growing over time: effectively a memory leak. Is there a way of monitoring the number of Disposable objects being tracked by a Lifetime Scope at any point in time. I'm interested in writing tool to help me find issues related to

Enumerating disposables tracked by an Autofac lifetime

吃可爱长大的小学妹 提交于 2019-12-22 13:52:01
问题 Autofac uses lifetime scopes as a way of disposing of all of the components created during a unit of work. While this is a powerful feature, it is easy to write code that doesn't dispose the lifetime scopes properly, which results in the number of tracked disposables growing over time: effectively a memory leak. Is there a way of monitoring the number of Disposable objects being tracked by a Lifetime Scope at any point in time. I'm interested in writing tool to help me find issues related to

Factory pattern without service locator

无人久伴 提交于 2019-12-22 13:05:44
问题 I am currently stuck at trying to write a factory class that doesn't rely on service location. The only other alternative I can think of is to use constructor injection to inject all possible instances, but that may lead to surprises as classes are passed via reference. It is also possibly going to be costly and messy once the number of possible providers grow. The providers themselves are full complex classes that have their own dependencies so manual construction is out of the picture.

Unity 2.0 IOC Configuration about Generic class

不想你离开。 提交于 2019-12-22 11:19:13
问题 I want some Repository class extend one common generic class to perform some common operation, problem is: how to config a UserExRepository type in config file. public class UserExRepository : Repository<User>, IUserEx { public UserExRepository(Context context):base(context){ } } public abstract class Repository<TObject> : IRepository<TObject> where TObject : class { protected Context Context = null; public Repository(Context context) { Context = context; } // do some common operation about

Building a WinForms Application using MVC and Ninject as IoC Container

久未见 提交于 2019-12-22 09:59:26
问题 I am having to re-write a large WinForms application and I want to use MVC to allow increased testing capability etc. I want to also adopt Ninject as my IoC container as it is lightweight, fast and will increase the exstensibility of my application going forward. I have done a great deal of reading and I have managed to make a start on the arcitecture of this new application. However, I am not sure i have the right idea when using Ninject. The code... Starting with Program.cs and related

Autofac Binding at Runtime

感情迁移 提交于 2019-12-22 08:44:29
问题 I currently use Autofac to do simple constructor injection without any issues. However what I would like to know is how to resolve dependencies at runtime. The example below shows multiple ways in which we can export a document. With simple constructor injection the concrete implementation of IExport is resolved at runtime. However what need to do is to resolve IExport on a user selection from a dropdown list which will happen after the construction of my container. Is there any examples of

Linq to SQL DataContext Windsor IoC memory leak problem

心已入冬 提交于 2019-12-22 08:41:13
问题 I have an ASP.NET MVC app that creates a Linq2SQL datacontext on a per-web-request basis using Castler Windsor IoC. For some reason that I do not fully understand, every time a new datacontext is created (on every web request) about 8k of memory is taken up and not released - which inevitably causes an OutOfMemory exception. If I force garbage collection the memory is released OK. My datacontext class is very simple: public class DataContextAccessor : IDataContextAccessor { private readonly

Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib

谁说胖子不能爱 提交于 2019-12-22 08:29:58
问题 I'm using Unity IoC (Microsoft.Practices.Unity) and I can compile fine, but I'm getting the following error at run time: Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The Unity version is: 3.0.1026.0 Is there a compatibility problem between .Net 4 and this version of Unity. Also, I get the same error when using Unity v2. If so, how might I go about resolving this issue? EDIT: Also, I

Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib

你说的曾经没有我的故事 提交于 2019-12-22 08:29:01
问题 I'm using Unity IoC (Microsoft.Practices.Unity) and I can compile fine, but I'm getting the following error at run time: Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The Unity version is: 3.0.1026.0 Is there a compatibility problem between .Net 4 and this version of Unity. Also, I get the same error when using Unity v2. If so, how might I go about resolving this issue? EDIT: Also, I