Castle Windsor resolve ienumerable and name

Castle Windsor resolve ienumerable and name

Content Index :

Castle Windsor resolve ienumerable and name
Tag : chash , By : GunnarHafdal
Date : November 27 2020, 09:01 AM

Hope this helps Firstly you will need to register the CollectionResolver.
Secondly I suggest you either change the constructor of CacheOrderRepo to explicitly reference LocalOrderRepo or define a different abstraction (e.g. ILocalOrderRepo) for it.
public class CacheOrderRepo : IOrderRepository
    private readonly IEnumerable<IOrderRepository> realTimeRepos;
    private readonly LocalOrderRepo localRepo;

    public CacheOrderRepo(IEnumerable<IOrderRepository> realTime, LocalOrderRepo localRepo)
        this.realTimeRepos = realTime;
        this.localRepo = localRepo;
var container = new WindsorContainer();
container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));

var service = container.Resolve<IOrderRepository>();

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to resolve Castle.Windsor and MoQ version conflicts for Castle.Core assembly

Tag : development , By : Lauren Kirschner
Date : March 29 2020, 07:55 AM
To fix this issue In my project I need to use simultaneously Castle.Windsor and Moq dlls. Windsor requires Castle.Core also to be referenced in the project. , Problem can be solved using assembly binding - App.config:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" />
    <bindingRedirect oldVersion="" newVersion="" />

How to resolve with different implimentation using windsor castle

Tag : .net , By : Erwin
Date : March 29 2020, 07:55 AM
I hope this helps . You can register the 2 implementation with different names and then can pass the name while calling Resolve method. http://castleproject.org/container/documentation/trunk/manual/windsortypedocs/Generated_IWindsorContainer.html#IWindsorContainer_Methods5
Check this section in windsor docs

Castle Windsor - how to resolve by name?

Tag : development , By : acolomba
Date : November 14 2020, 05:16 PM
it fixes the issue Okay, I think I've found a possible solution, partly using the approach detailed here which shows how it is possible to register Func<>s with Windsor.
First, I register a delegate (Func<>) that uses the container to resolve by name:-
Container.Register(Component.For<Func<string, IHubProxy>>()
                   .Instance(name => Container.Resolve<IHubProxy>(name))
               .UsingFactoryMethod((kernel, context) => hubConnection.CreateHubProxy("FooHub"))
               .UsingFactoryMethod((kernel, context) => hubConnection.CreateHubProxy("BarHub"))
public class SomeClass
    private IHubProxy _fooHub;
    private IHubProxy _barHub;

    public SomeClass(Func<string, IHubProxy> hubProxyFactory)
        _fooHub = hubProxyFactory("FooHub");
        _barHub = hubProxyFactory("BarHub");

Windsor castle 3.2 resolve performance

Tag : chash , By : user94076
Date : March 29 2020, 07:55 AM
wish of those help How much time it takes to resolve an object graph depends on a lot of factors, such as:
The size of the object graph The registered lifestyles of components and the location of those lifestyles in the graph (obviously if the root object is a singleton, resolving is really fast) The amount of work you do in your constructors
Container       |  ms.
Simple Injector | 0.01
StructureMap    | 0.50
Autofac         | 0.77
Unity           | 1.04
Castle Windsor  | 3.96
Ninject         | 5.03

Conditional Resolve in Castle Windsor

Tag : chash , By : Bo.
Date : March 29 2020, 07:55 AM
seems to work fine Rather than returning a null reference (as you say in your comment), I'd instead return a null service implementation. In other words, an implementation that is a no-op or just a passthrough. This way the class consuming the service doesn't need to add in any logic that it really should not know anything about (i.e. whether or not the service is valid to use in a given situation).
To do this, you can just use the UsingFactoryMethod functionality to make the decision of which service to return at runtime. Taking the first registration that you want to be conditional:
// The URL for this service can be configured during runtime. 
// If it is null or empty it should not be resolved.
    .UsingFactoryMethod((kernel, context) => 
        if (!string.IsNullOrEmpty(SiteInformation.PublishUrl))
            return ServiceFactory.CreateService<ITestService>(
        return kernel.Resolve<INullTestService>();
Related Posts Related QUESTIONS :
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • "The attribute names could not be inferred from bind attribute 'bind-value'" exception in Blazor
  • How to fix ''System.ArgumentException" in c#?
  • C#. Ref returning delegate for ref extension method
  • Swashbuckle Swagger generate an actual guid
  • Trying to make thousands of database calls simultaneously - they stack instead of running concurently
  • run mstest from cmd using testcontainer
  • How to make M:N (many-to-many) relationship where both M and N are the same entities?
  • Consume COM DLL from multiple clients
  • Convert json string response representing UCHAR array to Byte array
  • Why does this LinqPad program produce different results on the second run?
  • ServiceStack how to use MaxLoginAttempts feature
  • What does "late-bound access to the destination object" mean?
  • How to load appsettings.json inside a Static class based on deploy environment so that I can use in other class librarie
  • dynamically add images to view
  • Are static extension methods on User object safe?
  • Process thousands of database calls simultaneously
  • Trying to decrypt a string with public key(not private) using bouncycastle in .net
  • How to retrieve the name of an usb device
  • Query many-to-many related data using Entity Framework Core
  • ASP.NET MVC : how to find the view from a controller?
  • Inconsistent behaviour using Entity Framework for ASP.NET MVC app vs windows service
  • AutoFixture Customize vs Build
  • How to change textbox location at the click of a mouse in live mode?
  • How can I deserialize a XML file without defining the parent node?
  • asp.net core how decrease class coupling
  • ASP.NET Core Razor Pages Routing With parameters
  • String Escaping With $ Interpolation and @ Encoding
  • ConfigurationManager in ASP.NET WebAPI tested with HttpServer
  • Top down shooting in Unity 2D don't work as I want it to
  • Use own redirectUri when the Authentication expires
  • Using "foreach" in string array c#
  • "Object reference not set to an instance of an object" for create multiply models on one view
  • Get data passed trought pushAsync
  • Selector expression dynamic on IQueryable
  • Logut with SignInManager not calling method
  • Exit event handler with MessageBox OK button
  • Can not load view from Custom Renderer Xamarin Forms
  • Looking for a .Net ORM
  • Cost of SortedDictionary.Count
  • All possible combinations of n items selected randomly from a set of x items (algorithm)
  • Displaying process percentage on DOS screen
  • C# Importing Large Volume of Data from CSV to Database
  • c# control location precision
  • Printing to Zebra printer gives faint and blurry images
  • How to avoid stepping into dll code file?
  • Programmaticaly prevent Vista desktop search (WDS) from indexing pst files placed on mapped network drives
  • Is there anyway to reduce IsolatedStorage capacity in Silverlight?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com