unity-container

Where is Microsoft.Practices.Unity package?

左心房为你撑大大i 提交于 2019-12-03 10:36:17
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. There is no such package in Nuget. I have the packages listed below from Unity stack installed: <package

Dependency Injection composition root and decorator pattern

我怕爱的太早我们不能终老 提交于 2019-12-03 10:05:43
I'm getting StackoverflowException 's in my implementation of the decorator pattern when using dependency injection. I think it is because I'm "missing" something from my understanding of DI/IoC. For example, I currently have CustomerService and CustomerServiceLoggingDecorator . Both classes implement ICustomerService , and all the decorator class does is use an injected ICustomerService but adds some simple NLog logging so that I can use logging without affecting the code in CustomerService while also not breaking the single responsibility principle. However the problem here is that because

Wpf usercontrol with parameterised constructor

坚强是说给别人听的谎言 提交于 2019-12-03 10:05:37
问题 We are using Microsoft Unity and dependency injection and so we have parametrised constructor for the usercontrol. How to inject this dependency into usercontrol using XAML? I have added the usercontrol in XAML as below. xmlns:usrRefundArrivalProcessor="Ttl.Refunds.Wpf.Dashboad.Application.Usercontrols;assembly=Ttl.Refunds.Wpf.Dashboad.Application" 回答1: Dependency injection does not imply parameterized constructors. In fact, if you look at the samples that come with Unity, most of the

Using unity xml config to register an interface with nested generics

若如初见. 提交于 2019-12-03 09:43:01
If I have a class that implements a generic interface it works fine to configure it using the unity xml config. public interface IReader<T> { } public class Fund { } public class FundReader : IReader<Fund> { } and the unity xml: <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <namespace name="System.ComponentModel" /> <namespace name="TestUnityIssue" /> <assembly name="TestUnityIssue" /> <container> <register type="IReader[Fund]" mapTo="FundReader" /> </container> </unity> And this works just using the following code: var container = new UnityContainer().LoadConfiguration();

Using Unity's dependency injection in (data) annotations

那年仲夏 提交于 2019-12-03 08:51:35
I am using Unity and have a Model tagged with data annotations: public class SomeModel { [SlackDisplayName("ED0CAD76-263E-496F-ABB1-A4DFE6DEC5C2")] public String SomeProperty { get; set; } } This SlackDisplayName property is a child class of DisplayName, which resolves a static Display Name for the property. I just wanted to make that dynamically by having this criteria fulfilled: The use of this annotation is possible. I can implement multilingual applications using that annotation. Language templates get identified by a GUID I must not pass a culture id to the annotation So furthermore, my

Unity Dependency Injection with Global Web API Filter Attribute

浪尽此生 提交于 2019-12-03 07:30:08
Referencing this CodePlex unity article I was able to get filter attribute working with a WebAPI controller as follows: [MyFilterAttribute] public class TestController : ApiController {} However, if I want to apply my filter attribute across all actions with a GlobalConfiguration it gets stripped of the injected dependency: public class MyFilterAttribute : ActionFilterAttribute { [Dependency] public MyDependency { get; set; } public override void OnActionExecuting(HttpActionContext actionContext) { if (this.MyDependency == null) //ALWAYS NULL ON GLOBAL CONFIGURATIONS throw new Exception(); } }

Avoiding Service Locator Antipattern with legacy app not designed for IOC

懵懂的女人 提交于 2019-12-03 07:26:25
问题 I have read often that Service Locators in IOC are an anti-pattern. Last year we introduced IOC (Ninject specifically) to our application at work. The app is legacy, it's very big and it's fragmented. There are lots of ways a class, or a chain of classes can get created. Some are created by the web framework (which is custom), some are created by nHibernate. Lots are just scattered around in weird places. How would we handle the different scenarios and not come up with something thats not at

asp.net identity 2.0 unity not resolving default user store

我与影子孤独终老i 提交于 2019-12-03 06:15:10
问题 i get the following exception when trying to configure Unity using Unity.Mvc5 with an MVC 5 application using Identity 2.0 and the Identity 2.0 Samples boilerplate. i have read this SO Configure Unity DI for ASP.NET Identity and i'm still not clear on what i'm missing. What am i doing wrong here? The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping? [ResolutionFailedException: Resolution of the dependency failed,

UnityContainer.Resolve or ServiceLocator.GetInstance?

孤人 提交于 2019-12-03 06:01:10
问题 It could seem a stupid question because in my code everything is working, but I've registered a singleton this way with my Unity container _ambientContainer : _ambientContainer.RegisterType<Application.StateContext>(new ContainerControlledLifetimeManager()); In order to avoid to use my local field, I use: get { return ServiceLocator.Current.GetInstance<Application.StateContext>(); } inside my get property to get an instance of my object. This way I get always the same instance ( Application

How to configure unity container to provide string constructor value?

怎甘沉沦 提交于 2019-12-03 05:58:24
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 DadContainer for this assertion to pass? Thank you You should provide a parameterless constructor: public