ObjectDataSource .NET Core Dependency Injection

2 posts, 0 answers
  1. Paul
    Paul avatar
    4 posts
    Member since:
    Oct 2019

    Posted 26 Oct Link to this post

    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. Nasko
    Admin
    Nasko avatar
    1070 posts

    Posted 29 Oct Link to this post

    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
Back to Top