unity-container

MVC Unity Reset DI when user logs out

核能气质少年 提交于 2019-12-11 06:24:33
问题 I am using unity as my IoC and when the application loads up I setup my initial DI in the global.asax that my login screen needs. When the user logs in I then setup my main DI that creates all the DI stuff for the rest of the application. One of the objects I am creating is storing the user details from the login screen and I am using that dto to inject into my services to be used for authorisation. The issue I have is when the user logs out. I need to dispose of the dto that contains the

Unity ResolveAll Generics Interface

萝らか妹 提交于 2019-12-11 06:07:27
问题 I'm using Unity IoC, I'd like to register mapping of non generic class to generic interface. After that I'd like to use ResolveAll method for retrieve all registration associated to generic interface. This is the sample code: interface ISample<out T> { } class Ca : ISample<int> { } class Cb : ISample<string> { } class Program { static void Main(string[] args) { var container = new UnityContainer(); container.RegisterType<ISample<int>,Ca>(); container.RegisterType<ISample<string>, Cb>(); var

Write to multiple files Enterprise Library Logger

心已入冬 提交于 2019-12-11 05:49:16
问题 Is it possible using Enterprise Library Logger to log to multiple files grouped by date ? For example Trace-08-22-2011.log, Trace-08-23-2011.log. 回答1: Yes, but not with the TraceListeners that ship with Enterprise-Library. What you need is a custom TraceListener or at least TraceListenerData which is used indirectly as a trace listener factory (GetCreationExpression). The easiers way to do what you've described is to inherit from RollingFlatFileTraceListenerData and overrice

Managed Debugging Assistant 'DisconnectedContext'

你说的曾经没有我的故事 提交于 2019-12-11 04:57:53
问题 After setting up a unit test in VS2105 which created some COM objects using Unity I started getting the following error: Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\te.processhost.managed.exe'. I had a quick look to see if anyone else had the same problems and a lot of the solutions to the problem were either to fire off the test in it's own thread or change

Time taken between Application_BeginRequest and MVC Controller constructor is too long

我的梦境 提交于 2019-12-11 04:20:04
问题 I have an MVC page request that takes 1200ms between Application_BeginRequest and Application_EndRequest. The bulk of this time is between the Application_BeginRequest and the constructor of the MVC controller - 900ms. I am using Unity as the dependency injector and EF. The controller has 12 repositorys passed in on the constructor. 07:26:40,260 - context_BeginRequest 07:26:40,260 - Application_BeginRequest 07:26:41,180 - Constructor 07:26:41,180 - OnAuthentication 07:26:41,196 -

unity resolve instance at web api controller

可紊 提交于 2019-12-11 04:16:25
问题 Is there any way to resolve the instance of a class at the controller level? I would like to override the previous instance created by unity and assign this new value via the controller. Problem is I am not sure how to access the unity container in the web app controller. Here is my code: Repository: public class UserRepository: IUserRepository { private UserInformation _userInfo; public UserRepository(string headerValue) { _userInfo = LoadUserData(headerValue); } public UserInformation

What's the difference between IUnityContainer.Resolve() and ResolvedParameter when configuring constructor arguments?

ぃ、小莉子 提交于 2019-12-11 04:13:36
问题 Some code I'm updating uses Unity which is a bit new to me, although I get the general principles. One interface is registered like this: _container.RegisterType<ISomething, Something>( new ContainerControlledLifetimeManager(), new InjectionConstructor( new ResolvedParameter<ITypeA>(), new ResolvedParameter<ITypeB>(), _container.Resolve<ITypeC>() ) ); I'm confused the distinction between new ResolvedParameter<ITypeB>() and _container.Resolve<ITypeC>() - can someone make it clearer what the

IoC Register Instance Issue with MVC3, Unity & NHibernate - (Unity.MVC3 lib from codeplex)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 04:07:43
问题 I'm using the Unity.MVC3.dll from codeplex and am attempting to register an instance of a NHibernate ISession per request. As per the Unity MVC3 docs I should just have to use the HierarchicalLifetimeManager to accomplish this: var container = new UnityContainer(); container.RegisterInstance<ISession>(SessionFactory.OpenSession(), new HierarchicalLifetimeManager()); container.RegisterControllers(); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); SessionFactory is a

error: Make sure that the controller has a parameterless public constructor webapi

萝らか妹 提交于 2019-12-11 03:55:58
问题 I am using webapi, unity, and mvc. I am getting the error "Make sure that the controller has a parameterless public constructor". I have seen treads on similar problems but still can't get it to work. I have installed unity.webapi and seem to have all the necessary references: Microsoft.Practices.Unity - runtime: v4.0.30319, version: 3.5.0.0 Microsoft.Practices.Unity.Mvc - runtime: v4.0.30319, version: 3.5.0.0 Unity.WebApi - runtime: v4.0.30319, version: 5.1.0.0 System.Web.Http - runtime: v4

Unity registration fails after iisreset

吃可爱长大的小学妹 提交于 2019-12-11 02:42:12
问题 I am registering a load of dependencies like so. container.RegisterTypes(AllClasses.FromLoadedAssemblies(), WithMappings.FromMatchingInterface, WithName.Default, overwriteExistingMappings: true); This registers things fine and the web api endpoints are properly configured. If I do iisreset or simply wait for a bit then things fail with The error message is not terribly helpful "exceptionMessage": "An error occurred when trying to create a controller of type 'ApiController'. Make sure that the