castle-windsor

castle PerRequestLifestyle not recognize

早过忘川 提交于 2019-12-01 05:48:27
New to Castle/Windsor, please bear with me. I am currently using the framework System.Web.Mvc.Extensibility and in its start up code, it registered HttpContextBase like the following: container.Register(Component.For<HttpContextBase>().LifeStyle.Transient.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current))); What I wanted to do is to change the behavior and change the lifestyle of httpContextBase to be PerWebRequest. so I have change the code to the following: container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new

How do I Instantiate component as Singleton at registration?

喜欢而已 提交于 2019-12-01 04:52:29
I can imagine this might be quite straight forward to do in Castle but I'm new to the technology and have been Googling for hours with no luck! I have the following: container.Register( Component.For<MySpecialClass>().UsingFactoryMethod( () => new MySpecialClass()).LifeStyle.Singleton); Now quite rightly this is being lazy-loaded, i.e. the lambda expression passed in to UsingFactoryMethod() isn't being executed until I actually ask Castle to Resolve me the instance of the class. But I would like Castle to create the instance as soon as I have registered it. Is this possible? Moshe Levi You can

NUnit integration tests and dependency injection

最后都变了- 提交于 2019-12-01 04:39:28
I'm currently making use of Castle Windsor version 2.1 as my container and would like to perform integration tests using the services registered with it. Currently, I do this my using the Common Service Locator to retrieve my service instance and perform my integration tests against it as such: var myService = ServiceLocator.Current.GetInstance<IMyService>(); // do stuff with myService What I'd ideally like to do is have my service dependencies injected into my NUnit test fixture automatically. Spring seems to offer this functionality , but I can't locate anything similar using Castle. Can

Setting up Inversion of Control (IoC) in ASP.NET MVC with Castle Windsor

末鹿安然 提交于 2019-12-01 03:43:31
I'm going over Sanderson's Pro ASP.NET MVC Framework and in Chapter 4 he discusses Creating a Custom Controller Factory and it seems that the original method, AddComponentLifeStyle or AddComponentWithLifeStyle , used to register controllers is deprecated now: public class WindsorControllerFactory : DefaultControllerFactory { IWindsorContainer container; public WindsorControllerFactory() { container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle"))); // register all the controller types as transient var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()

How do I get the current Castle Windsor container?

给你一囗甜甜゛ 提交于 2019-12-01 03:15:30
I am a Castle Winsor Noob. I have a WebForm project that is a hot mess. I am trying to resolve a dependency to test user registration. How do I get to the current WindsorContainer? IWindsorContainer container = ???; IRegistrationLogic registrationLogic = container.Resolve<IRegistrationLogic>(); _registrationLogic.Register(); Here is my Bootstrapper: public class WindsorConfigTask : ICastleBootstrapperTask { public void Execute() { Container.AddFacility<WcfFacility>(); Container.Register( Component.For<IProcessMessageRequest>() .ActAs( new DefaultClientModel { Endpoint = WcfEndpoint.ForContract

SignalR with IoC (Castle Windsor) - which lifetime for hubs?

点点圈 提交于 2019-12-01 03:03:11
问题 I'm just starting out with SignalR, and have created a custom resolver for SignalR, so I can use Castle Windsor to inject dependencies via hub constructors. I kind of assumed that I would only need to register the dependencies, but I found that it was also necessary to register the hubs themselves before my app would work. Is this expected? If so, what lifetime should I use for hubs? 回答1: By default SignalR does not register each hub with the dependency resolver. Instead it uses an

Disposing of ViewModels in Caliburn Micro and Castle Windsor

泪湿孤枕 提交于 2019-12-01 03:02:42
问题 I'm using Castle-Windsor as my container in a Caliburn-Micro Silverlight app. My ViewModel objects are reasonably chunky as they call WCF services and a bunch of other stuff. Therefore, when a window is closed I want to call container.Release(viewModel) so Castle can manage the whole decommission/disposal process, respecting the various lifecycles configured (as outlined in this post). In my AppBootstrapper I have overridden GetInstance as follows: protected override object GetInstance(Type

How do I Instantiate component as Singleton at registration?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 02:22:28
问题 I can imagine this might be quite straight forward to do in Castle but I'm new to the technology and have been Googling for hours with no luck! I have the following: container.Register( Component.For<MySpecialClass>().UsingFactoryMethod( () => new MySpecialClass()).LifeStyle.Singleton); Now quite rightly this is being lazy-loaded, i.e. the lambda expression passed in to UsingFactoryMethod() isn't being executed until I actually ask Castle to Resolve me the instance of the class. But I would

Which IOC Container runs in medium trust

◇◆丶佛笑我妖孽 提交于 2019-12-01 01:56:32
问题 Hi I am trying to get a website running with Mosso that has Castle Windsor as my IOC, however I am getting the following error. [SecurityException: That assembly does not allow partially trusted callers.] GoldMine.WindsorControllerFactory..ctor() in WindsorControllerFactory.cs:33 GoldMine.MvcApplication.Application_Start() in Global.asax.cs:70 My questions are Does Castle Windsor run under medium trust? Can I download the DLL's without having to recompile with nant? (as I don't have this set

How to use Castle.Windsor in an assembly loaded using reflection

让人想犯罪 __ 提交于 2019-12-01 00:56:40
Let's say I have a library Lib.dll, which uses Castle.Windsor to initialize its services. I have a main application App.exe, which loads Lib.dll on runtime using reflection. App.exe does not know the location of Lib.dll beforehand, it is only known at runtime. In this case, when App.exe loads Lib.dll and Lib.dll initialize its services, a System.TypeInitializationException exception is thrown, because Castle.Windsor cannot find the service type. Castle.MicroKernel.SubSystems.Conversion.ConverterException: Could not convert from 'Lib.TheServiceClass' to System.Type - Maybe type could not be