Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6329607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:42:06+00:00 2026-05-24T17:42:06+00:00

I want to create an object with a constructor containing predicate and func objects

  • 0

I want to create an object with a constructor containing predicate and func objects in the xml config using spring. The Predicate and the Func arguments should point to a method of another configured object. How is this possible using Spring.net? I was not able to find a solution or hint in the documentation…

A sample constructor would be:

MyClass(Predicate<TInput> condition, Func<TInput, TOutput> result)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:42:08+00:00Added an answer on May 24, 2026 at 5:42 pm

    I solved the problem using an intermediate “factory” inspired by the suggestion of thekip but leaving the object requiring the predicate and func in the constructor (MyClass in the example above) untouched. This solution keeps the “problem” of handling delegates in spring outside of the implementation of MyClass (in opposite of the suggestion of thekip, but thanks for your answer).

    Here is my way to configure such a situation (setting delegates in Spring.Net, using object based factory pattern).

    The MyDelegator class a sample implementation for predicate/func to use
    (object here, but could be anything else fitting to the predicate/func params):

    public class MyDelegator
    {
        // for the predicate Predicate<TInput> condition, implemented with object
        public bool Condition(object input) 
        {
            ...
        }
    
        //for the Func<TInput, TOutput> result, implemented with object
        public object Evaluate(object input) 
        {
            ...
        }
    }
    

    … then you need a container for the object with the predicate and or func (could
    be in seperate classes, too) …

    public class MySpringConfigurationDelegateObjectContainer
    {
        private readonly Predicate<object> condition;
        private readonly Func<object, object> evaluate;
    
        public MySpringConfigurationDelegateObjectContainer(MyDelegator strategy)
        {
            condition = strategy.Condition;
            evaluate = strategy.Evaluate;
        }
    
        public Predicate<object> GetConditionMethod()
        {
            return condition;
        }
    
        public Func<object, object> GetEvaluateMethod()
        {
            return evaluate;
        }
    }
    

    … and this can be configured in Spring.Net xml this way

      <!-- a simple container class, just has the object with the method to call -->
      <object id="Container" type="MySpringConfigurationDelegateObjectContainer">
        <constructor-arg name="myDelegateObject">
          <!-- put the object with the delegate/func/predicate here -->
          <object type="MyDelegator" />
        </constructor-arg>
      </object>
    

    And now you can use this anywhere in your config for objects with predicate/func
    (no need to change the class requiring the predicate/func)

      <object id="NeedAPredicateAndFuncInConstructor" type="...">
        ...
        <constructor-arg name="condition">
          <object factory-method="GetConditionMethod" factory-object="Container" />
        </constructor-arg>
        <constructor-arg name="result">
          <object factory-method="GetEvaluateMethod" factory-object="Container" />
        </constructor-arg>
        ...
      </object>
    

    That’s it. Any suggestions to improve this solution? Maybe, Spring.net already has a generic solution for this…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new object using Class::DBI. One of the fields of
I want to know why cant we create object if the constructor is in
I want to create object on the client side of aspx page. And i
I want to create light object data-package to pass between client and server applications.
I want to create an object in python that is a collection of around
I want to dynamically create object of HtmlDivElement in my jsf managed bean and
I want to create an object, let's say a Pie. class Pie def initialize(name,
I want to create an object with a non-enumerable property(a property that does not
I want to create a Map object that can lose value only if we
If I want to create a .NET object in the powershell I write something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.