unity-container

MVC Integration tests with Unity IoC

瘦欲@ 提交于 2019-12-21 17:31:47
问题 Am trying Unity IoC, after using constructor based DI. Problem is trying to get integration tests working. http://patrick.lioi.net/2013/06/20/streamlined-integration-tests/ "Running your integration tests should exercise as much of the real system as is reasonably possible" Patrick above describes setting up an IoC inside the MVC Unit test project.. but I'm stuck as to how to implement public class HomeController : Controller { readonly IWinterDb db; // Unity knows that if IWinterDb interface

Custom MembershipProvider: No parameterless constructor defined for this object

落花浮王杯 提交于 2019-12-21 12:38:15
问题 I have a custom MembershipProvider class that inherits from MembershipProvider that takes two parameters: public class CustomMembershipProvider : MembershipProvider { private readonly ISecurityRepository _securityRepository; private readonly IUserRepository _userRepository; public CustomMembershipProvider(ISecurityRepository securityRepository, IUserRepository userRepository) { ... } public override MembershipUser GetUser(string username, bool userIsOnline) { ... } ... etc } The config file

ASP.NET MVC 3 Dependency Injection - Controllers, Views & Action Filters

南笙酒味 提交于 2019-12-21 12:22:35
问题 I'm trying to get dependency injection working in an ASP.NET MVC 3 application using Microsoft Unity. First i have implemented my own IDependencyResolver and activated it in my Global.asax file like so: DependencyResolver.SetResolver(new UnityDependencyResolver(container)); I found that i don't need to do anything else to get controller injection (via both the constructor and [Dependency] attribute) to work. With the default view engine i also found i could get the [Dependency] attribute to

Unity framework DependencyAttribute only works for public properties?

此生再无相见时 提交于 2019-12-21 09:18:18
问题 I was trying to clean up some accessability stuff in my code, and inadvertently broke Unity dependency injection. After a while I realized that I marked some public properties that I didn't really want exposed outside my DLLs to internal. Then I started getting exceptions. So it seems that using the [Dependency] attribute in Unity only works for public properties. I suppose that makes sense since the internal and private props wouldnt be visible to the Unity assembly, but feels really dirty

Creating objects using Unity Resolve with extra parameters

谁说我不能喝 提交于 2019-12-21 07:24:16
问题 I'm using Prism, which gives be the nice Unity IoC container too. I'm new to the concept, so I haven't gotten my hands all around it yet. What I want to do now is to create an object using the IoC container, but passing an extra parameter too. Allow me to explain with an example..: I have a class that takes a commands object. This is registered in the IoC container, so it will handle it nicely: public class Person { public Person(IApplicationCommands commands) { .. } .. } Person person =

Lazy resolution of dependency injection

 ̄綄美尐妖づ 提交于 2019-12-21 05:28:04
问题 I have .net classes I am using unity as IOC for resolving our dependencies. It tries to load all the dependencies at the beginning. Is there a way (setting) in Unity which allows to load a dependency at runtime? 回答1: There's even better solution - native support for Lazy<T> and IEnumerable<Lazy<T>> in the Unity 2.0. Check it out here. 回答2: I have blogged some code here to allow passing 'lazy' dependencies into your classes. It allows you to replace: class MyClass(IDependency dependency) with

Using Unity's dependency injection in (data) annotations

本秂侑毒 提交于 2019-12-21 02:54:09
问题 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

WPF + MvvM + Prism

痴心易碎 提交于 2019-12-20 17:18:21
问题 I am new in the Wpf & Mvvm world , but I have found a couple of examples and just found that there is some different way to instantiate the model. I would like to know the best/correct way to do it. both ways are using Unity What I've foud: var navigatorView = new MainView(); navigatorView.DataContext = m_Container.Resolve<INavigatorViewModel>(); m_RegionManager.Regions["NavigatorRegion"].Add(navigatorView); What I did: var navigatorView = m_Container.Resolve<MainView>; m_RegionManager

Prism, connecting Views and ViewModels with Unity, trying to understand it

こ雲淡風輕ζ 提交于 2019-12-20 12:28:36
问题 Creating the View and View Model Using Unity Using Unity as your dependency injection container is similar to using MEF, and both property-based and constructor-based injection are supported. The principal difference is that the types are typically not implicitly discovered at run time; instead, they have to be registered with the container. Typically, you define an interface on the view model so the view model's specific concrete type can be decoupled from the view. For example, the view can

What are the InjectionMembers in RegisterType() calls for?

邮差的信 提交于 2019-12-20 11:54:06
问题 I've been working with Microsoft's Unity IOC container. There are a bunch of overloads for the RegisterType() method all looking similar to IUnityContainer RegisterType(Type t, params InjectionMember[] injectionMembers); I'm wondering when the injectionMembers parameters are for? I couldn't find any documentation for the them (even though they're in every overload) and none of the sample code I looked at use them. Am I missing something here? Are they not commonly used or did I just miss the