Injecting dependencies into business objects

4 posts, 1 answers
  1. Martin
    Martin avatar
    1 posts
    Member since:
    Dec 2013

    Posted 13 Feb 2014 Link to this post

    Hi,

    I'm using on the server side the REST service. The report is using an object data source. I have created a business object OrderReadService

        [DataObject]
        public class OrderReadService
        {      
            [DataObjectMethod(DataObjectMethodType.Select)]
            public IEnumerable<Order> Get()
            {
                    ....          
            }
        }

    This works so far fine. But I need to inject this object with some dependecies. Something like:

        [DataObject]
        public class OrderReadService
        {      
    public OrderReadService(IRepository repo, IUserProvider userProvider)
    {
    ...
    }

            [DataObjectMethod(DataObjectMethodType.Select)]
            public IEnumerable<Order> Get()
            {
                ....          
            }
        }


    Is there any place where I can override the business object initialization ?

    The server side looks like this http://www.telerik.com/help/reporting/telerik-reporting-rest-implementing-http-service.html

  2. Answer
    Nasko
    Admin
    Nasko avatar
    1071 posts

    Posted 18 Feb 2014 Link to this post

    Hello Martin,

    Currently there is no option to control the business object initialization.
    On a side note, in case the data retrieval method contains parameters, the Parameters collection of the ObjectDataSource should be used to pass values to them at runtime. For more information please check the Using Parameters with the ObjectDataSource Component help article.

    Regards,
    Nasko
    Telerik

    New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

  3. Dmitry
    Dmitry avatar
    1 posts
    Member since:
    Jan 2020

    Posted 21 Jan Link to this post

    Hello,

    Was this possibility implemented? It's still actual and necessary.

    Or I would like to know recommended pattern how to work with dependencies. Obviously it's bad solution to create for example DB context explicitly and manually in every business object class.

  4. Neli
    Admin
    Neli avatar
    251 posts

    Posted 24 Jan Link to this post

    Hi Dmitry,

    Basically, the Reporting engine uses System.Reflection to invoke the data retrieving functionality described in the ObjectDataSource. The latter accepts parameters: Using Parameters with the ObjectDataSource Component and in some cases, it may be possible to use dependency injection -for example, if the injected values are primitive and can be passed as Report Parameter values. But still, injecting dependencies into business objects is not possible out-of-the-box. Note that if the DataMember is not provided, the DataSource constructor will be used and the parameters will be passed to this constructor.

    Regards,
    Neli
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top