Coder Social home page Coder Social logo

drum's People

Contributors

filipw avatar pmhsfelix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

drum's Issues

Support multiple routes for the same action

Currently for a configuration like this:

[Route("api/product/{searchCriteria}]
[Route("api/product/type/id/{guid}"]
public async Task<IHttpActionResult> GetProduct()
{
}

you will receive the exception:

Multiple routes for the same action. Action: <action>, previous route <route1>, new route: <route2>

Is it possible to actually support multiple routes?

In case of more than 1 route is found use say DefaultAmbiguousRouteResolver which returns routes.First(), or an implementation of IAmbiguousRouteResolver passed to MapHttpAttributeRoutesAndUseUriMaker() if any.

Other way to support such scenario is to respect the RouteAttribute.Name property, they should be different when applied to the same action.

Array parameters

When an action has an IEnumerable parameter the code to handle complex objects is iterating over the properties instead of the items within the array.
Simple test:

    [Route("")]
    public void GetByIds(int[] id) { }

    [Fact]
    public void Can_make_uri_for_action_with_array()
    {
        var uri = _uriMaker.UriFor(c => c.GetByIds(new []{ 1, 2, 3 }));
        Assert.Equal("http://example.org/api/UriMakerTests/resources?id=1&id=2&id=3",uri.ToString());
    }

Actual: http://example.org/api/UriMakerTests/resources?Length=3&LongLength=3&Rank=1&SyncRoot=System.Int32[]&IsReadOnly=False&IsFixedSize=True&IsSynchronized=False

Also would be helpful if it worked for an object parameter that has list properties like:

public class PageInfo
{
    public int page { get; set; }
    public int count { get; set; }
    public List<int> someList { get; set; }
}

I took a crack at a fix but hit a wall building the RouteValueHandler. Thanks for the work on this, link generation in web api is really weak without drum.

Use Drum in BaseController<T> to allow generic route references

I am using a custom DirectRouteProvider that overrides the GetActionRouteFactories method of the DefaultDirectRouteProvider in order to allow inheritance in attribute routing.

This allows me to use attribute routing in a BaseController to define route for every action that should be available to all the inheriting controllers (TestController : Basecontroller).

This works fine until I try to generate links to generic routes.

I can't name the routes dynamically based on the generic type as this is not allowed in attributes in C#.

I can't define a name for these routes as there would be many routes with the same name (for all inheriting controllers).

I thought I could use your package as Drum works well with unnamed routes, but I can't seem to find a way to use the uriMaker from inside the BaseController to reference the route from the inheriting controller in a generic way.

Is there a way out?

Support async action in UriFor()

Currently it has the following signature:

public Uri UriFor(Expression<Action<TController>> action);

so if action is async such as

public async Task<IHttpActionResult> Get();

then a compiler warning appears:

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

So maybe Expression<Task<Action<TController>> could be added?

Support complex types

Say you have a controller with two actions:

[Route("api/user/{searchCriteria}")]
public async Task<IHttpActionResult> GetUser([FromUri]UserSearchCriteria searchCriteria)

and

[Route("api/user")]
public async Task<IHttpActionResult> PutUser(UserModel userModel)

In second you want to return a uri to first:

var uriMaker = Request.TryGetUriMakerFor<UserController>();
var uri = uriMaker.UriFor(c => c.GetUser(new UserSearchCriteria { UserId = user.UserId }));
return Created(uri, user);

Actual result:

http://localhost:8086/api/user/Models.UserSearchCriteria

Expected result:

http://localhost:8086/api/user/???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.