castle-windsor

Conditional dependency resolution in ASP.NET MVC using castle windsor

99封情书 提交于 2019-12-13 19:38:12
问题 I am trying to solve this case in our code where I need to resolve the dependency at runtime based on a specific condition, such as if certain query string value exist or not. Let say I have a controller AuthenticationController and I have authentication service having two flavours of it. public class AuthenticationController { private readonly IAuthenticationService authenticationService; public AuthenticationController(IAuthenticationService authenticationService) { this

Convert this Castle Windsor Installer to Ninject to register all repositories

蹲街弑〆低调 提交于 2019-12-13 17:24:26
问题 I have this in my MVC2 app but I think I might move to Ninject as its becoming more popular and Castle Windsor seems a tad over complicated. How would I do something like this in Ninject however? Maybe Castle Windsor is more developed and I should stick with it. container.Register(AllTypes.FromThisAssembly() .Where(type => type.Name.EndsWith("Repository")) .WithService.DefaultInterface() .Configure(c => c.LifeStyle.PerWebRequest)); 回答1: What you want to do can be done with the Ninjec

Castle Windsor Resolve method: why pass arguments? What are they for?

匆匆过客 提交于 2019-12-13 15:17:33
问题 I am confused by Castle Windsor resolve method. This method allows me to pass almost anything. Is the value submitted in the resolve method passed along and used in the constructor of the object which is eventually resolved to, or is this value used to help the resolver determine what concrete implementation to use? For example, if I have the following snippet... var _container = new WindsorContainer(); _container.Install(FromAssembly.This()); var MyProcessor = _container.Resolve<IProcessor>

Chaining containers with StructureMap

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:18:10
问题 Is it possible to link containers together in StructureMap like it is in WindsorContainer.AddChildContainer()? I want to achieve having 3 container levels; - 1 page request level - 1 session level - 1 application level These would then be chained together so only one instance request would be made to the "base level" container. The levels of container are unimportant really, just whether there is the ability to link them together. 回答1: This seems to do the trick, not sure if there is a better

Intercepting method called from a method of the same object

安稳与你 提交于 2019-12-13 07:43:10
问题 Here's the situation: /// <summary> /// A business logic class. /// </summary> public class BusinessClassWithInterceptor : BusinessClass, IBusinessClass { /// <summary> /// Initializes a new instance of the <see cref="BusinessClassWithoutInterceptor"/> class. /// </summary> /// <param name="logger">The logger.</param> public BusinessClassWithInterceptor(Logger logger) : base(logger) { } /// <summary> /// Displays all cows. /// </summary> public void DisplayAllCows() { this.Logger.Write(

Creating a Castle Windsor Controller Factory and GetControllerInstance is never called

こ雲淡風輕ζ 提交于 2019-12-13 05:00:44
问题 I am introducing DI into my MS MVC application and I am having trouble getting the controllers instantiated from within my custom Controller Factory. It seems that the overridden "GetControllerInstance" is not being called. Can someone tell me what I am missing? My Controller Factory: public class WindsorControllerFactory : DefaultControllerFactory { readonly IWindsorContainer container; public WindsorControllerFactory(IWindsorContainer container) { this.container = container; var

Castle Windsor IoC property injection. Using property from BaseClass inside ChildClass constructor

妖精的绣舞 提交于 2019-12-13 04:39:40
问题 I have a base class as following public class BaseClass { public ISomeObject Property { get; set; } } and ChildClass inherited from BaseClass.I need to use Property from BaseClass inside ChildClass constructor, but it's not initialized by IoC as I want and has value null. And if I use it inside ChildClass's methods, Property is initialized. What am I doing wrong? Here is how I register ISomeObject in IoC container container.Register( Component.For<ISomeObject>() .ImplementedBy<WebSomeObject>(

Console.WriteLine is not working after Resolve()

我与影子孤独终老i 提交于 2019-12-13 04:17:24
问题 This code gives no error or warning during execution. but it ignores the console.read() function, i am newer with windsor. is it really a bug or the simple behavior of windsor ? using System; using Castle.Windsor; using Castle.MicroKernel.Registration; namespace CastleProject { class Program { internal interface ILogger { void log(string message); void showMethod(); } internal interface Ishowing { void checkInterface(); } class Logger : ILogger { public void log(string message) { Console

Ioc/DI - Why do I have to reference all layers/assemblies in application's entry point?

折月煮酒 提交于 2019-12-13 04:17:23
问题 (Related to this question, EF4: Why does proxy creation have to be enabled when lazy loading is enabled?). I'm new to DI, so bear with me. I understand that the container is in charge of instantiating all of my registered types but in order to do so it requires a reference to all of the DLLs in my solution and their references. If I weren't using a DI container, I wouldn't have to reference the EntityFramework library in my MVC3 app, only my business layer, which would reference my DAL/Repo

External Controllers and Castle

橙三吉。 提交于 2019-12-13 03:45:28
问题 FIXED: I'm leaving this in case some other Joe Schmo needs it. In the controller factory you need to register the controller so that it can be found when called. container.Kernel.AddComponent("ExternalResources", typeof(InteSoft.Web.ExternalResourceLoader.ExternalResourceController), LifestyleType.Transient); Do it like so: // Instantiate a container, taking configuration from web.config container = new WindsorContainer( new XmlInterpreter(new ConfigResource("castle")) ); // Also register all