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

ObjectDataSource .NET Core Dependency Injection

2 Answers 384 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 26 Oct 2019, 11:24 AM

Is it possible to use .net core dependency injection into the object set as the data source to an ObjectDataSource?

Such that...

 

[DataObject]
class Products
{
    private readonly IProductRepo _repo;
 
    public Products(IProductRepo repo
    {
         _repo = repo;
    }
 
 
    [DataObjectMethod(DataObjectMethodType.Select)]
    public IEnumerable<Prodcut> GetProducts()
    {
       _repo.GetProducts();
    }
}

2 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 29 Oct 2019, 09:34 AM

Hello Paul,

The ObjectDataSource component accepts parameters: Using Parameters with the ObjectDataSource Component. In theory it is possible to use dependency injection into the object.

If the scenario is more complex, you can also call the GetProducts() method yourself and assign the resulting IEnumerable directly to the Report.DataSource property.

Regards,
Nasko
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
2
Vitaliy
Top achievements
Rank 1
answered on 30 Jan 2020, 01:37 PM

Hello Nasko,

you wrote "In theory it is possible to use dependency injection into the object". Please, continue with solution. Could you provide a demo project? Or post here the code examples?

Tags
General Discussions
Asked by
Paul
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Vitaliy
Top achievements
Rank 1
Share this question
or