How do I register an IBindingTypeConverter in ReactiveUI - reactiveui

I'm attempting to use the "new" binding code for ReactiveUI and when I do wire my view model property to my control I get the following error:
Additional information: Can't two-way convert between <type1> and <type2>. To fix this, register a IBindingTypeConverter
So... how do I register an IBindingTypeConverter ? I'm struggling to find an comprehensible example.
n.b. the code that's throwing the error is not relevant to this question, it may in itself be wrong but that is an entirely different issue

The way to do it is via Splat's service locator:
Locator.CurrentMutable.RegisterConstant(
new MyCoolTypeConverter(), typeof(IBindingTypeConverter));
Update: If you're using RxUI 5.x, it's "RxApp.CurrentMutable"

Related

How can i set the api version on a generic controller when loading a plugin?

I have some plugin's which are basically input and output type definitions. I have a generic controller which i can add to the mvc pipeline. All works fine.
but I'm having trouble setting the api version on this generic controller. I know you can set this based upon an attribute on top of the controller class. But since you can't have this dynamic (attribute) don't allow it, i have no way to set the version for each instance of the generic controller.
Currently i just compile the controller for each instance on runtime and register i using the roslyn compiler.
is there a way to set the api-version somewhere in the pipeline of registering controllers in the mvc pipeline and endup with different api versions endpoints.
This can be achieved by using the Conventions API. It was designed to support this exact type of scenario:
https://github.com/microsoft/aspnet-api-versioning/wiki/API-Version-Conventions
This will only work on closed-generics, but it shouldn't be too much work to make that happen. Here's a couple of basic examples:
// typed, closed generic
options.Conventions.Controller<GenericController<PlugIn1>>().HasApiVersion(1,0);
// untyped, closed generic
var controllerType = typeof(GenericController<>).MakeGenericType(new []{typeof(PlugIn1)});
options.Conventions.Controller(controllerType).HasApiVersion(1,0);
You can also author your own custom conventions a la IControllerConvention. This approach could be used to version all controllers that inherit from GenericController<>. Then you just need to add it to the conventions like this:
options.Conventions.Add(new PlugInControllerConvention());
Hopefully that's enough to get you started. Feel free to ask more questions.

how to properly handle OData complex type relationships

Trying to build a WebAPI 2 / OData v4 service around a typical default Northwind database, using Entity Framework 6.1
My WebApiConfig is unhappy about "complex type relationships":
An exception of type 'System.InvalidOperationException'
occurred in System.Web.OData.dll
but was not handled in user code
Additional information: The complex type 'ODataProductService.Models.Order_Detail'
refers to the entity type 'ODataProductService.Models.Product'
through the property 'Product'.
Obviously, in any given database, these relationships are very likely to occur.
What is the proper way of hanlding this?
Here is how I gat this resolved:
1) added the following statements to my WebApiConfig.cs:
I have made a GitHub repo with a working solution in it:
builder.EntitySet<Customer>("Customers");
builder.EntitySet<Product>("Products");
builder.EntitySet<Order>("Orders").EntityType.HasKey(o => o.OrderID);
builder.EntitySet<Order_Detail>("Order Details").EntityType.HasKey(od => od.OrderID);
builder.EntitySet<CustomerDemographic>("CustomerDemographics").EntityType.HasKey(cd => cd.CustomerTypeID);
I have also made a repo with a working solution:
https://github.com/eugene-goldberg/ODataProductService/
The Readme file pretty much describes what to pay attention to.
You could also use the containment feature of OData V4. Using containment, you can avoid defining an entity set for Order_Detail.

BindingResolutionException while creating services to access database

We are trying to implement architecture suggested in following article in order to make our application extensible
http://dfg.gd/blog/decoupling-your-code-in-laravel-using-repositiories-and-services
The article divides the models into following
Entities - normal Eloquent classes
Repositories - these use Entities to get data
Services - Contain Business logic
To try out the architecture we are trying to access a small table
We have created following classes
app/models/entities/Reminder.php //normal Eloquent model
app/models/repositories/reminder/ReminderInterface.php
app/models/repositories/reminder/ReminderRepository.php
app/models/repositories/reminder/ReminderRepositoryServiceProvider.php
app/models/services/reminder/ReminderFacade.php
app/models/services/reminder/ReminderService.php
app/models/services/reminder/ReminderServiceServiceProvider.php
We are struck at following error
Illuminate \ Container \ BindingResolutionException
Target [Repositories\Reminder\ReminderInterface] is not instantiable.
Can someone please guide what may be going wrong?
Our code is exactly the same as in the article. I tried to be brief in this description as posting code of all 7 classes is not sensible. Please let me know if you need any details.
Option 1
You might be missing a binding:
App::bind('Repositories\Reminder\ReminderInterface', 'Repositories\Reminder\ReminderRepository');
If you don't tell Laravel which implementation of your Interface you need it to Instantiate it will try to instantiate ReminderInterface, which is not instantiable, as the error says.
Option 2
If you are binding it in your service provider, you have to make sure your service provider is being executed, by adding it to app/config/app.php?

jaydata/jaysvcutil 1.3.5 inverseProperty support for WebAPI

I've seen Missing inverse property in asp.net webapi odata $metadata and the WebAPI $metadata I'm dealing with behaves as described in this article: it doesn't reuse associations for bi-directional navigation properties.
When using jaysvcutil 1.3.5 all navigational properties come up as $$unbound.
$data.Entity.extend('API.Models.Document', {
...
'Document_Versions': {
'type':'Array',
'elementType':'API.Models.Document_Versions',
'inverseProperty':'$$unbound' }
});
Other than manually updating the inverseProperty information is there anything to get the desired result automatically?
Update based on #Robesz answer
Manually adding inverseProperty information to the static .js converted by JaySvcUtil is doable, but I'm asking if there's an option to accomplish that with the dynamic conversion as well.
There seems to be to options
make modifications to the .NET WebAPI. Might be challenging, because their seem to be good reason for their implementation, but maybe somebody already successfully did that.
modifying the conversion XSLT that JayData using to take that behavior into account.
We've just arrived to the same results with WebAPI OData, but after editing the generated context file manually and adding the inverseProperty everything is working fine
This should be most probably handled by extending JayData's XSLT conversion. I've created an issues for that on https://github.com/jaydata/jaydata/issues/155.

Check Using JSTL/Spring-MVC tag regarding Spring Binding Error

I am trying to find a way by which i can check if there is any binding error and based on them i want to show some messages to the user in Spring-MVC. i know one way of this like
<spring:hasBindErrors name="userName">
</spring:hasBindErrors>
but this seems to be with respect to a specific filed of my form, what i want is to check if there is any binding error at all for the current input form or not?
i have also experience of Struts2 and they have a very convient method hasError() which allow a developer to see if there is any error at all for the input fields.
Is there such method defined for Spring-MVC validation or not?
Not an expert of Spring-MVC as i have used it very rarely but if i am correct all you want an equivalent of bindingResult.hasErrors() and if i am correct all you need to use
hasBindErrors tag. For more details refer to the doc
hasBindErrors
Hope this might help you

Resources