unity-container

How implement Strategy/Facade Pattern using Unity Dependecy Injection Web API

巧了我就是萌 提交于 2019-12-02 18:52:06
问题 How tell to Unity.WebApi dependency injection framework, inject the correct class in the correct controller? DI Project Container public class UnityContainerConfig { private static IUnityContainer _unityContainer = null; public static IUnityContainer Initialize() { if (_unityContainer == null) { _unityContainer = new Microsoft.Practices.Unity.UnityContainer() .RegisterType<IMyInterface, MyClass1>("MyClass1") .RegisterType<IMyInterface, MyClass2>("MyClass2") } } -MVC PROJECT- public static

How to register service class with multiple repository types in Bootstrapper file?

佐手、 提交于 2019-12-02 15:38:07
问题 There are 4 parameterized constructor of one of my service layer(ProductService). And all of the 4 constructors are injected with different repository types. public class ProductService : IProductService { private IUserDal<Users> mUserDal { get; set; } private IItemDal<Item> mItemDal { get; set; } private IRoleDal<Role> mRoleDal { get; set; } private IBranchDal<Branch> mBranchDal { get; set; } public ProductService (IUserDal<Users> userDal) { mUserDal = userDal; } public ProductService

Ninject vs Unity for DI [closed]

≯℡__Kan透↙ 提交于 2019-12-02 14:05:42
We are using ASP.net MVC. Which of these is the best DI framework Ninject or Unity and why? Last time I looked at either of them I found Ninject slightly better. But both have their drawbacks. Ninject has a better fluent-configuration scheme. Unity seems to rely mostly on XML configuration. Ninject's main drawback is that it requires you to reference Ninject.Core everywhere in your code to add [Inject] attributes. If I may ask, why are you limiting your choices to these two? I think Castle.Windsor, Autofac and StructureMap are at least as good or better. roberocity I know this is an old

Microsoft Unity- Issue With Resolve

落花浮王杯 提交于 2019-12-02 13:59:00
问题 I am looking to do this: container.Resolve(); When it does this, its going to inject a IDependency into the underlying entity object. However, the dependency stored within the container requires an object of type DependencyValue, which is supplied a value from a DependencyFactory. So long story short, the issue I'm having is that I need to, when Unity creates the instance of class implementing IDependency, that I would be able to take over and insert a custom value not in the container. Is

interface and cannot be constructed on Unity config

余生颓废 提交于 2019-12-02 13:27:18
I have trouble to use Unity on this project. The error is The current type, Business.Interfaces.IPersonnelBusiness, is an interface and cannot be constructed. Are you missing a type mapping? I've updated the Unity to thge latest version because of stackoverflow issue and I saw that RegisterComponents has changed to lazy loaded one here is the Global asax: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // Unity

Does unity just make clasess with out needing anything registered?

◇◆丶佛笑我妖孽 提交于 2019-12-02 13:21:42
问题 I am watching Mike Tautly's awesome intro to Prism. It was all making sense, but I got a bit confused in the sixth video. He has his view class's constructor take a parameter of the ViewModel. He then says that unity will fill this in for us (ie construct it). In the past he has had to register this kind of thing (ie IMyClass registered to MyClass). But he did not do that for the ViewModel. The only difference I can see is that the dependency to the ViewModel was not an interface, but rather

Does MS PnP Unity Scan for Assemblies Like StructureMap?

烈酒焚心 提交于 2019-12-02 11:54:59
问题 In Using StructureMap 2.5 to scan all assemblies in a folder, we can see that StructureMap uses AssembliesFromPath() to explicitly look for types to resolve. What is the equivalent of this in Microsoft Unity? Because Unity is such a generic term, searching for documents about this online is not that easy. Update: Unity has something called an Assembly Matching Rule but its description does not communicate to me that it scans folders . 回答1: The Assembly Matching Rule is used for applying

Dependency Injection Container for each Class Library

巧了我就是萌 提交于 2019-12-02 10:44:41
问题 So, this is the first time I'm dealing with DI, please correct me if I misunderstood the whole DI thingy. These are few of my projects: Web Application/ Web API Project - Depends on Service Class + inject Automapper (Configuration only applicable for current project) Service (Class Library) - Depends on Data Class + inject Automapper (Configuration only applicable for current project) Data (Class Library) My intention was to have each project having its own DI container (says Unity DI). I'm

Random “Missing type map configuration or unsupported mapping.” Error in Automapper

筅森魡賤 提交于 2019-12-02 09:37:35
Please see this post for the solution. Ok, I finally figured it out. The: AppDomain.CurrentDomain.GetAssemblies() piece of my code sometimes does not get my mapping assembly so while it is missing I get an error. Replacing this code by forcing the app to find all assemblies solved my problem. My Entity: /// <summary> /// Get/Set the name of the Country /// </summary> public string CountryName { get; set; } /// <summary> /// Get/Set the international code of the Country /// </summary> public string CountryCode { get; set; } /// <summary> /// Get/Set the coordinate of the Country /// </summary>

How implement Strategy/Facade Pattern using Unity Dependecy Injection Web API

元气小坏坏 提交于 2019-12-02 08:58:35
How tell to Unity.WebApi dependency injection framework, inject the correct class in the correct controller? DI Project Container public class UnityContainerConfig { private static IUnityContainer _unityContainer = null; public static IUnityContainer Initialize() { if (_unityContainer == null) { _unityContainer = new Microsoft.Practices.Unity.UnityContainer() .RegisterType<IMyInterface, MyClass1>("MyClass1") .RegisterType<IMyInterface, MyClass2>("MyClass2") } } -MVC PROJECT- public static class UnityConfig { public static void RegisterComponents() { GlobalConfiguration.Configuration