castle-windsor

Can you register an existing instance of a type in the Windsor Container?

岁酱吖の 提交于 2019-12-23 07:05:56
问题 In the Windsor IOC container is it possible to register a type that I've already got an instance for, instead of having the container create it? 回答1: There is a AddComponentInstance method on the Container's Kernel property. From the Unit Tests: [Test] public void AddComponentInstance() { CustomerImpl customer = new CustomerImpl(); kernel.AddComponentInstance("key", typeof(ICustomer), customer); Assert.IsTrue(kernel.HasComponent("key")); CustomerImpl customer2 = kernel["key"] as CustomerImpl;

Why does Castle Windsor constructor crash on Windows Server 2003 with a manifest?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 04:27:00
问题 As part of getting our application ready for Windows7, we recently added a manifest to our our user interface's exe. It runs ok on Windows7. However, now when I try to run the signed exe on Windows Server 2003, the program crashes during startup. I've looked at the crash dump, and it seems to by failing in the constructor of Castle.Core.Resource.ConfigResource which is called from the Program.Main method. If this is included in the manifest: <compatibility xmlns="urn:schemas-microsoft-com

WcfFacility Sequence contains no elements

十年热恋 提交于 2019-12-23 03:07:32
问题 I keep getting a Sequence contains no elements error when trying to install my wcf services. here is the code in my global.asax: _container = new WindsorContainer(); _container.Register(Component.For<IWindsorContainer>().Instance(_container)) .AddFacility<WcfFacility>() .Install(Configuration.FromAppConfig()) .Install(FromAssembly.InDirectory(new AssemblyFilter(HttpRuntime.BinDirectory, "Web*.dll"))); here is my system.servicemodel section in web.config: <system.serviceModel>

Castle Windsor: How to prevent circular references in factory-created objects were the created objects refers back to the factory

旧城冷巷雨未停 提交于 2019-12-23 02:24:30
问题 I am using windsor castle as my IoC container, and has run in to a bit of a problem. This is best explained in code, so I´ll give it a try. I have a factory class, that should provide me with implementations of a certain interface: public interface IObjectCreatorFactory { IObjectCreator GetObjectCreator(Type objectType); } public interface IObjectCreator { T CreateObject<T>(IDataRow data); bool SupportsType(Type type); } Implementation of the factory class could look like this, though I am

Register all classes from base on up in Castle Windsor using Fluent interface

心不动则不痛 提交于 2019-12-22 12:44:28
问题 I have an abstract base class Search . An abstract class IndexedRepositorySearch descends from Search . An abstract class FacetSearch descends from IndexedRepositorySearch . Concrete classes IngredientFacetSearch and RecipeFacetSearch descend from FacetSearch . Currently we're registering everything that descends from Search with Castle Windsor as follows: AllTypes.FromAssembly(assembly) .BasedOn<Search.Search>() .WithServiceBase() .WithServiceSelf() .LifestyleTransient()

Linq to SQL DataContext Windsor IoC memory leak problem

心已入冬 提交于 2019-12-22 08:41:13
问题 I have an ASP.NET MVC app that creates a Linq2SQL datacontext on a per-web-request basis using Castler Windsor IoC. For some reason that I do not fully understand, every time a new datacontext is created (on every web request) about 8k of memory is taken up and not released - which inevitably causes an OutOfMemory exception. If I force garbage collection the memory is released OK. My datacontext class is very simple: public class DataContextAccessor : IDataContextAccessor { private readonly

IIS7 & Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule registering problems

若如初见. 提交于 2019-12-22 06:35:41
问题 UPDATE: In Windsor 2.5 the assembly name is Castle.Windsor not Castle.MicroKernel I'm trying to deploy an ASP.NET MVC app to IIS7 and I'm getting this error: Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '' to the section on your web.config My httpModules contains: <httpModules> <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel"/> </httpModules> system.webServer

Why use IKernel over IWindsorContainer?

旧巷老猫 提交于 2019-12-22 03:22:45
问题 I have seen in several code examples where people have used IKernel rather than use IWindsorContainer . Why is this? Here is one example: http://docs.castleproject.org/(S(kwaa14uzdj55gv55dzgf0vui))/Windsor.Windsor-tutorial-part-two-plugging-Windsor-in.ashx In the above example it came to bite me because I added a subresolver Container.Kernel.Resolver.AddSubResolver( new CollectionResolver(Container.Kernel, true)); that will allow me to inject collections... but yet it wasnt working. I figured

How do I get Web API / Castle Windsor to recognize a Controller?

旧时模样 提交于 2019-12-21 23:00:21
问题 I found out why the placeholder "Home Controller" was getting called here I commented out the reference to HomeController in RouteConfig.cs and added a Controller that I want it to call instead: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //If get 404 error re: favicon, see http://docs.castleproject.org/(X(1)S(vv4c5o450lhlzb45p5wzrq45))/Windsor.Windsor-tutorial-part-two-plugging-Windsor-in.ashx or

Castle Windsor Fluent API: Define dependency explicitly

一世执手 提交于 2019-12-21 21:38:23
问题 Given the below configuration Container.Register(Component.For<A>().Named("foo")); Container.Register(Component.For<B>().Named("foobar")); Container.Register( AllTypes.Pick() .FromAssemblyNamed("MyAssembly") .If(t => t.Name.EndsWith("ABC")) .Configure(c => c.LifeStyle.Is(LifestyleType.Transient)) .WithService.Select(i => typeof(I)) ); Container.Register( AllTypes.Pick() .FromAssemblyNamed("MyAssembly") .If(t => t.Name.EndsWith("123")) .Configure(c => c.LifeStyle.Is(LifestyleType.Transient))