Inheritance support in the RegisterType() method

34 views
Skip to first unread message

Alexey Solonets

unread,
Apr 19, 2012, 6:28:08 AM4/19/12
to extdirec...@googlegroups.com
Hi Gian Marco!
I saw you have the BaseClass class with the BaseMethod in the ExtDirectHandler.Tests project. So i want to BaseMethod could be also available by RPC. So i made this pull request https://github.com/gimmi/extdirecthandler/pull/14 The main difference is new RegisterType<T>(bool inherit) method that will include inherited members in derived classes.

Sample use case: i have base generic class (let's call it BaseRepository) that can Add, Update and Delete records in my database:

public class BaseRepository<T>
where T: class
{
    public IQueryable<T> Get()
    {
        // get all records
    }

    public T Add(T item)
    {
        // adding methods
    }

    public T Update(T item)
    {
        // updating methods
    }

    public void Delete(int id)
    {
        // deleting methods
    }
}

And then i want to create a lot of child repositories that must have base functionality and may have some extra functionality:

public class UserRepository: BaseRepository<User>
{

}

public class OrderRepository: BaseRepository<Order>
{
    public IEnumerable<Order> GetOrdersByDate(DateTime date)
    {
         return this.Get().Where(o => o.Date == date);
    }
}

//...

After this i register both UserRepository and OrderRepository and want that all their methods (include inherited) to be available in ExtJS.

I know this example is very simple but you catched the idea :) 
That is why a made a fork. What do you think on this?

Gian Marco Gherardi

unread,
Apr 19, 2012, 8:45:15 AM4/19/12
to extdirec...@googlegroups.com
Hi, i don't like much the idea of having all methods from the whole hierarchy exposed (with the only exclusion of object's member) because this can represent a security flaw.

One possible solution for supporting inherited method is change the ReflectionConfigurator so that it expose all methods decorated with the DirectMethodAttribute, and search both in class member and inherited members.

his way exposing a method become more explicit.

What do you think?

Gian Marco Gherardi
http://gianmarco.gherardi.me

Alexey Solonets

unread,
Apr 20, 2012, 12:10:24 AM4/20/12
to extdirec...@googlegroups.com
Hi Gian Marco!

Yeah, of course if i will register Repositories directly it can really represent a security flaw. But in real life i will never do this :) In real projects i have n-tier structure with DAL, BLL, REST Controllers and client-side. Each layer just makes it's job. Controllers are simple and have some base methods to help communicate with ExtJS. Every call to a controller is intercepted and checked if it is available for the caller.

We can look at the ASP.NET MVC architecture. Microsoft's guys created the System.Web.Mvc.Controller class. We can create a hierarchy of these controllers and all their methods from base controller will be available for REST methods. I'm sure they thought twice about security issues. And now i just want to replace System.Web.Mvc Controllers with my DirectControllers (in your terms - Actions). I'm sure it will be great (considering that this feature is optional). 

Gian Marco Gherardi

unread,
Apr 21, 2012, 7:11:59 AM4/21/12
to extdirec...@googlegroups.com
Yes i understand the requirement, but what is your feeling about my proposed solution?

Alexey Solonets

unread,
Apr 24, 2012, 12:20:01 AM4/24/12
to extdirec...@googlegroups.com
Hi, sorry i respond you slowly.

I like your solution. It will be much less code to change.

So what will happen if you implement this feature? Will i have to mark methods in base classes with DirectMethod attribute and may not do this in derived classes? Isn't it confusing? Maybe make this attribute required everywhere?

Gian Marco Gherardi

unread,
Apr 24, 2012, 1:12:03 AM4/24/12
to extdirec...@googlegroups.com

My idea is to only expose decorated method, both in the class and all superclasses.

This is IMO a more clear and explicit behavior.

The downside of this is that this change is not backward compatible, and so can cause trouble during extdirecthandler update in existing projects.

GMG (sent from mobile)

Alexey Solonets

unread,
Apr 24, 2012, 8:27:49 AM4/24/12
to extdirec...@googlegroups.com
I agree, backward compatibility is a problem. 

Anyway, what is your plan implementing inheritance support? Would you like me to fork again or maybe you want to do this by yourself?

Sent from my iPad

Gian Marco Gherardi

unread,
Apr 24, 2012, 2:48:16 PM4/24/12
to extdirec...@googlegroups.com
i will try some implementation when i have some time.

You can of course create a pull request for this and i will be happy to review it.

If you can't wait to have this feature "officially" supported, you have the following options:
* Use the much more flexible LambdaConfigurator to configure ExtDirectHandler (check out this for an example)
* Create your own configurator by implementing IMetadata, and use it with ExtDirectHandler (but, please, if you do something useful, share it! :-) )

Gian Marco Gherardi
http://gianmarco.gherardi.me

Alexey Solonets

unread,
Apr 24, 2012, 3:29:52 PM4/24/12
to extdirec...@googlegroups.com
Ok, thanks for all your answers Gian Marco! I'll try to do one of these things when will come back home, on the next week. And of course will share :)

Sent from my iPad

Gian Marco Gherardi

unread,
May 5, 2012, 8:31:51 AM5/5/12
to extdirec...@googlegroups.com
The just released version 0.8.13 (available on NuGet) has this feature implemented.

Alexey Solonets

unread,
May 5, 2012, 10:35:26 AM5/5/12
to extdirec...@googlegroups.com
This is really good news! Thanks Gian Marco!

Sent from my iPad
Reply all
Reply to author
Forward
0 new messages