This is a migrated thread and some comments may be shown as answers.

Injecting dependencies into business objects

3 Answers 199 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 13 Feb 2014, 10:25 AM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 18 Feb 2014, 09:29 AM
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.

0
Dmitry
Top achievements
Rank 1
answered on 21 Jan 2020, 02:01 PM

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.

0
Neli
Telerik team
answered on 24 Jan 2020, 02:16 PM

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
Tags
General Discussions
Asked by
Martin
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Dmitry
Top achievements
Rank 1
Neli
Telerik team
Share this question
or