castle-windsor

Castle remoting sample - client throwing exception

邮差的信 提交于 2019-12-12 01:16:38
问题 I am using the sample from castle @ http://old.castleproject.org/container/facilities/trunk/remoting/containersconnected.html for "Scenario: Using the container on both endpoints and use the container components" The only update I have made to this is one line in the config files from type="Castle.Facilities.Remoting.RemotingFacility, Castle.MicroKernel" to type="Castle.Facilities.Remoting.RemotingFacility, Castle.Windsor" as suggested by Mauricio in question Castle remoting facility not

How to determine if a component is resolvable from an IHandlersFilter implementation

匆匆过客 提交于 2019-12-12 00:53:21
问题 I am trying to write a Castle Windsor v3 IHandlersFilter implementation that will filter out handlers that cannot be resolved. This is in an effort to optionally restore the old (pre-castle 3) behavior of ResolveAll (How to revert to old CollectionResolver behavior in Castle 3?) My question is, from the SelectHandlers method, what is the best way (if any) to determine which of the input IHandlers are resolvable? I have experimented with the IHandler.CanResolve method, but it takes parameters

Can I programmatically determine the database “context” to use based on user credentials?

北战南征 提交于 2019-12-11 21:18:51
问题 This is a followup to the question here, where the answer seems to refer to an overly-complicated and overly-specific (EF, which I'm not using - not even using an ORM). There has to be a more straightforward way around this common scenario than the smoke, mirrors, and sorcery hinted at in that answer. Note: I encased "context" in parenthesis because I'm not using EF, so it is not a literal "dbcontext" that I'm talking about here. So I got to wondering: Could I set a global variable for each

Unable to perform dependency injection in MVC 5 Web API project using Castle Windsor

╄→尐↘猪︶ㄣ 提交于 2019-12-11 20:45:48
问题 Below is the code for controller I want to instantiate using Windsor Castle. public class TestController : ApiController { private ITestService _testService = null; public TestController(ITestService testService) { _testService = testService; } public IList<TestClass> Get() { IList<TestClass> testObjects = _testService.GetAll().ToList(); return testObjects; } } I've written following code in Global.asax.cs protected void Application_Start() { ........................ InitializeServiceLocator(

Resolution-time arguments of same type in Castle Windsor

≡放荡痞女 提交于 2019-12-11 19:07:18
问题 When I try to pass two parameters that are of the same type like so: public IPercentage CreatePercentage(int part, int total) { return _container.Resolve<T>(new Arguments(part, total)); } To a constructor like so: public Percentage(int part, int total) { // ... } Then I get a System.ArgumentException: An item with the same key has already been added. How can I pass arguments of same type? The key thing is I would like to avoid using literal string names of the parameters to identify which

Resolving HttpRequestMessage with Castle Windsor

Deadly 提交于 2019-12-11 17:33:49
问题 I've tried following advice from existing posts to make HttpRequestMessage available as a constructor dependency for services in Web API: ASP Web Api - IoC - Resolve HttpRequestMessage Resolving HttpControllerContext with Castle Windsor This advice works fine if all the dependencies only have one constructor . But when a dependency has multiple constructors, dependency resolution fails. Any ideas how to extend the idea to work with multiple constructors? ======================= The existing

Specify component name to resolve from type factory at runtime

荒凉一梦 提交于 2019-12-11 15:54:22
问题 Suppose I have an interface: public interface IService { void DoThing(); } Now let's say I want to have a few implementations of this, so I can swap out which implmentation I want to use at runtime: container.Register(Component.For<IService>().ImplementedBy<IServiceImplementationOne>().Named("First")); container.Register(Component.For<IService>().ImplementedBy<IServiceImplementationTwo>().Named("Second")); container.Register(Component.For<IService>().ImplementedBy<IServiceImplementationThree>

Circular reference using IoC

元气小坏坏 提交于 2019-12-11 14:57:24
问题 I am using windsor castle as my IoC container, and has run in to a bit of a problem. First of all - i know about: Castle Windsor: How to prevent circular references in factory-created objects were the created objects refers back to the factory But since circular reference is considered as "Code Smell" and i should consider refactoring app architecture i am asking anyway. I have very similar situation: public class OperationsFactory { private GeneralSettingsManager m_generalSettings; private

How to resolve runtime dependencies in castle windsor for C#

若如初见. 提交于 2019-12-11 13:56:21
问题 I have a specific scenario here where I need to pass the connection string based on the user, because users may be mapped to the different databases based on his/her enterprise. This is the code I use to resolve the dependency with a static variable: public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( Component.For<IUserRepository>() .ImplementedBy(typeof(IKS.Dare.Optimix.Repository.EntityFramework.UserModule.UserRepository)) .DependsOn(Dependency

Castle Windsor PerWebRequest Lifestyle is not being honored

五迷三道 提交于 2019-12-11 13:06:52
问题 I'm working on a 3-tier MVC application. The data layer contains an EF4 code-first DbContext: public class MyDataContext : DbContext { // DbSet<>s... } There's also an interface and an implementation for DI: public interface IContextFactory { MyDataContext GetContext(); } public class ContextFactory : IContextFactory { readonly MyDataContext context; public ContextFactory(MyDataContext context) { this.context = context; } public MyDataContext GetContext() { return this.context; } } And a