OData has it's own built in methods, like 'contains' 'endswith' 'geo.intersects' and so on..
Is there a way to add my own custom method? So I could give it a name, parameters and the Expression I want it to be translated to.
Thank you!
If you're using C#, you can go with your custom methods with [WebGet] annotation and IQueryable as the result. Then you need to register them by SetServiceOperationRule on DataServiceConfiguration. After that you can go with api/service.svc/YourMethodName. Hope it helps.
Related
I'm a new Thymeleaf user, so, I'm sorry if this is a too basic question, but I've tried searching it and couldn't find any results.
I've been working to integrate Thymeleaf in a brazilian web portal product and I want to be able to do something like <div th:text="${myfunc('some val')}"></div> (calling a custom method from Thymeleaf).
I know that I can do <div th:text="${myobj.myfunc('some val')}"></div>, but I don't want to expose the method myfunc inside an object.
In the integration, I've already created a custom IContext to expose some custom variables (this is working perfectly).
How could I do that?
Thanks !
I managed to do that by implementing an IEngineContextFactory that returns an implementation of IEngineContext that contains the method I want to expose.
I am using web api 2.2 odata v4.0. I have a controller which has 3 methods.
For example GetA(), GetB() and GetC(). Which code should I use so that I will be able to call individual methods from the url ?
Also, how can I call a method GetA()? - as Get() is the default method that is being called in ODataController.
I used the code,
ODataRoute route = config.Routes.MapODataServiceRoute("odata", "odata",GetModel());
route.MapODataRouteAttributes(config); // This line threw an error sowing route does not have the method
MapODataRouteAttributes()
Please suggest me the solution.
Thanks
What do you need GetA(), GetB() and GetC() to do ? Are they for getting specific properties A, B and C? If so, you can take a look at the ODAtaAttributeRoutingSample. And if you want to know more about Web API OData, you can take a look at Sample Service implemented with Web API which is a complete project.
You have to work with the Action Attributes to specify other functions then those following the default rules.
routing with attributes
I am using MVC3, C#, ASP.NET4.5
I have created some ActionLink extension methods, mainly to implement URL hashing.
I have many ActionLinks around my application, and wondered whether it was possible to force the use of my own extension methods without altering the signature of the ActionLink in the many Views?
I have 2 approaches at present:
1) Specific Name ie ActionLinkHashed(
2) Unique signature ActionLink(true, "myLink","myAction","myController"...)
Both 1) and 2) could be implement by a global replace espcially 1). However I am sure there must be a better method.
Thoughts appreciated.
Thanks.
In general, you cannot overload any method on any class with another function with an identical signature. Otherwise, it would be ambiguous to the compiler which one was intended.
You will have to use a function with a different signature. It would be best to do that by using your own name, to avoid potential future collisions with the framework.
This is similar to the question asked at StructureMap - Override constructor arguments for a named instance, but different in the respect that I don't know the type at coding time and therefore cannot use the generic form of GetInstance().
So while:
ObjectFactory.With(IFoo).GetInstance<IBar>("foobar");
will work, there is apparently no way to call:
ObjectFactory.With(IFoo).GetInstance(typeof(IBar), "foobar");
I have a workaround using a private generic method and the MakeGenericMethod() on that private method's MethodInfo.
As you might imagine, I'm not really happy with that approach, but I cannot see any other way out of the situation.
The method you want is GetNamedInstance(), which is not available when you use the With() method. I'm sure it would not be too hard to add it, maybe you could email Jeremy Miller and see if he can add it in StructureMap 3. Or submit a patch :)
I have an action filter which i got from the below link
http://blog.wekeroad.com/blog/aspnet-mvc-securing-your-controller-actions/
there is something called "RequiresAuthenticationAttribute"
for this i need to write test case.
how can i do this? form some of the blogs i read that we need to mock httcontext.
How can i mock this? what is the procedure that i need to do? is there any link for this?
Don't use the [RequiresAuthentication] attribute from Rob's blog. It's meant for a very old pre-release version of MVC. Use the in-box [Authorize] attribute instead.
Since the [Authorize] attribute is written by the MVC team, you don't need to unit test its logic. However, if you want, you can verify that it's applied to your controllers or actions. Simply get the Type or MethodInfo you're interested in, then call its GetCustomAttributes() method to get instances of AuthorizeAttribute. You can inspect those instances for the values that you expect.
If you want, you can look at the source code of AuthorizeAttribute for information on writing your own filter. Additionally, you can look at the official unit test of this type, so if you do end up writing a filter you can use a similar method to write your own type's unit tests.