unity-container

Resolution failure on app reload in MVC4 + Unity

心已入冬 提交于 2019-12-24 03:06:00
问题 I'm working on an ASP.NET MVC4 application, using Unity 3 as DI framework. I designed the architecture in a modular way, creating several satellite library projects (facade, managers, DB adapters, etc.), all statically linked to the app (which means added as references to the web project). The reason behind such architecture is to allow reusage in other contexts (for instance a separate REST based backend service, implemented as a standalone web project). I'm using dependency injection, which

Proper way to dependency inject authenticated user to my repository class

隐身守侯 提交于 2019-12-23 17:36:04
问题 I am using a service layer with repository pattern. The controller has a dependency on the service layer, and the service layer has a dependency on the repository. I have to pass logged in user information to the repository layer for authorization purposes and am trying to determine the best approach for injecting the user information into the repository considering that I seem to have an extensive injection chain: controller -> service(s) -> repositories -> logged in user info. I guess the

Unity registration by convention with interface interceptor causes “[type] is not interceptable” exception

旧巷老猫 提交于 2019-12-23 12:16:00
问题 I want to register all classes that implements a specific interface into Unity with the WithMappings.FromMatchingInterface convention. In addition, I want all of the registered objects to be intercepted using an interface interception behaviour. The problem is that Unity also registers mappings between the concrete classes, and when those classes are resolved, an exception is thrown with the message: "[type] is not interceptable" I realise that resolving an object using the concrete class

Unregister Instance in Unity container

时光怂恿深爱的人放手 提交于 2019-12-23 09:33:25
问题 How can i unregister instance in unity container. I sure that it possible, but can't find solution in manual docs 回答1: There is no unregister. You can register a new instance on top of an existing one, and it'll replace the previous one with the newly registered instance. 来源: https://stackoverflow.com/questions/5992275/unregister-instance-in-unity-container

Testing if a Type has been registered in Unity

喜你入骨 提交于 2019-12-23 08:03:25
问题 Can I test if a type has been registered in a Unity container without calling for a Resolve and trapping the exception? 回答1: Unity 2.0 will have an IsRegistered method that you can use to find out if a type has been registered in the container. The Beta1 of Unity 2.0 is available on Codeplex as of Feb 10th. See the release notes and download it here; http://unity.codeplex.com/wikipage?title=Unity2%20Beta1 UPDATE: Downloaded and tested Unity 2.0 beta 1 on Feb 27th 2010, and it's by far

Entity Framework returning old data

天大地大妈咪最大 提交于 2019-12-23 07:16:14
问题 I have a problem with EF not returning the newest data in a 3 layered WPF application, and I suspect it has something to do with how I handle the lifetime of my context. This is the scenario: There are several repositories wrapped inside a UnitOfWork. There is also one service (MyService), which uses the UnitOfWork. This UnitOfWork must also be called from the UI directly, without passing through a service. In the ViewModel of my main window at some point I create a new window (using

Entity Framework returning old data

∥☆過路亽.° 提交于 2019-12-23 07:15:52
问题 I have a problem with EF not returning the newest data in a 3 layered WPF application, and I suspect it has something to do with how I handle the lifetime of my context. This is the scenario: There are several repositories wrapped inside a UnitOfWork. There is also one service (MyService), which uses the UnitOfWork. This UnitOfWork must also be called from the UI directly, without passing through a service. In the ViewModel of my main window at some point I create a new window (using

Unity - loadConfiguration, how to resolve only those configured

馋奶兔 提交于 2019-12-23 04:45:22
问题 What I am trying to achieve: Have Unity load the mappings from a configuration file, then in source code resolve the types which were loaded from said configuration file App.Config <register type="NameSpace.ITill, ExampleTightCoupled" mapTo="NameSpace.Till, NameSpace" /> <register type="NameSpace.IAnalyticLogs, NameSpace" mapTo="NameSpace.AnalyticLogs, NameSpace" /> Code IUnityContainer container; container = new UnityContainer(); // Read interface->type mappings from app.config container

Dependency injection in thread that create objects

拟墨画扇 提交于 2019-12-23 03:52:38
问题 If I have a thread that is started from the main application. In this thread events are generated. Everytime an event is generated an object is created. In that object a dependancy is needed so I want to inject that object. How can I pass this dependancy to the created object? Do I need to pass the depandancy downwards (and let the class that works in the thread know of the dependancy) or is there a nicer way to do this? I'm using Unity btw. 回答1: The safest way is to let each thread build a

Unity container creation slowdown on some machines

耗尽温柔 提交于 2019-12-23 03:49:11
问题 On my develop machine all ok, but when I try app on test machine with WinXp sp3 I encountered a problem. The method call contains the code below takes 1,5 minute var c = new UnityContainer(); Unity version 2.0.414.0 .Net Framework v 3.5 sp1 Does any one know how to fix it? Thanks 回答1: Does your test machine have internet access? If not, it could be hanging trying to verify the authenticode certificate on the binary. A quick test would be to build Unity from source and use that dll instead. If