unity-container

Where is Microsoft.Practices.Unity package?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 04:22:07
问题 An hour ago I updated my nuget packages for the solution I'm working on and I get the error message, thrown by Unity, that The type 'IUnityContainer' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'. Since then I have been googling to get some usable information about that where this package is. The articles, question around it are old, deals with 2.x version.

How to configure unity container to provide string constructor value?

眉间皱痕 提交于 2020-01-01 01:31:06
问题 This is my dad class public class Dad { public string Name { get;set; } public Dad(string name) { Name = name; } } This is my test method public void TestDad() { UnityContainer DadContainer= new UnityContainer(); Dad newdad = DadContainer.Resolve<Dad>(); newdad.Name = "chris"; Assert.AreEqual(newdad.Name,"chris"); } This is the error I am getting "InvalidOperationException - the type String cannot be constructed. You must configure the container to supply this value" How do I configure my

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 {

Resolving named dependencies with Unity

筅森魡賤 提交于 2019-12-30 08:34:50
问题 I have a service with 2 dependencies: a Repository and a Gateway (sms). I need to resolve 2 different versions of the service that only differ on one of the parameters passed to the gateway. The code is simplified to as follows public interface IService { string DoSomething(); } public interface IServiceFoo { string DoSomething(); } public interface IServiceBar { string DoSomething(); } public interface IRepository { } public class Repository : IRepository { } public interface IGateway {

Typical IoC container usage - passing data down the line

寵の児 提交于 2019-12-30 07:00:08
问题 I've recently started using an IoC container for the first time, but I'm not educated on the best practices for using it. More specificaly I'm using Unity in a C# .NET project, and I started using it because it came with Prism. I use the container to resolve the "top level" objects, and they get the correct objects injected based on the container. However, I can't see the best practice clearly when I have an object with children and children's children, and I need some data from the IoC

again about log4net and Unity IOC config

对着背影说爱祢 提交于 2019-12-30 03:27:07
问题 I've bumped through a few of these questions laying around various sites and the answers seem to be spun by l4n officianados toward the value of the lightweight wrapper that log4net 'is' (don't you get it?) and similar points of mind-boggling fact. However it seems that what users are asking for (and this is my question) is how to fit the log4net objet model into the registertype/registerinstance sequence in the fluent config interface. The goal here wouldn't be to re-wrap l4n, but simply to

Unity and ASP.NET WebForms - No parameterless constructor defined for this object

萝らか妹 提交于 2019-12-30 03:26:12
问题 Does anyone have any good examples of how to make Unity 1.2 or 2.0 work with ASP.NET WebForms? I thought I had this figured out, but evidently I'm missing something. Now I'm getting the error; "No parameterless constructor defined for this object". I remember getting this error a couple years ago, I and just don't remember what I did. Obviously Unity isn't working as it should because somewhere along the way I've forgotten something. Any help would be appreciated. Here's some of my code:

How to Resolve type based on end-user configuration value?

烈酒焚心 提交于 2019-12-28 17:31:28
问题 I have an interface (call it IAcmeService) that has multiple implementations. FileSystemAcmeService DatabaseAcmeService NetworkAcmeService The end-user needs to be able to select which implementation will be used and also save that selection. Currently I'm configuring my IOC container (Unity) to register all the known implemenatation with a name. container.RegisterType(of IAcmeService, FileSystemAcmeService)("FileSystemAcmeService") container.RegisterType(of IAcmeService, DatabaseAcmeService)

How to Resolve type based on end-user configuration value?

送分小仙女□ 提交于 2019-12-28 17:31:12
问题 I have an interface (call it IAcmeService) that has multiple implementations. FileSystemAcmeService DatabaseAcmeService NetworkAcmeService The end-user needs to be able to select which implementation will be used and also save that selection. Currently I'm configuring my IOC container (Unity) to register all the known implemenatation with a name. container.RegisterType(of IAcmeService, FileSystemAcmeService)("FileSystemAcmeService") container.RegisterType(of IAcmeService, DatabaseAcmeService)

Unity Register For One Interface Multiple Object and Tell Unity Where to Inject them

◇◆丶佛笑我妖孽 提交于 2019-12-28 13:35:52
问题 Hi I have been having trouble trying to tell Unity that for an Interface if it has multiple implementations , I want it to inject them in different classes.Here is what I mean: Let's say I have an interface IProductCatalogService and two implementations ProductCatalog : IProductCatalogService and ProductCatalogService : IProductCatalogService . How would I go about telling Unity that for Class A I want in my constructor passed an instance of type ProductCatalog and for Class B I want an