MVC5 reading Config values without using System.Web - asp.net-mvc

I keep reading that the new MVC avoids using System.Web by default as that used to add lots of extra stuff automatically.
Does that mean that in order to read the config file now in MVC5,
one should use from System.Net instead?
Thanks...

It should be:
string key = System.Configuration.ConfigurationManager.AppSettings.Get("AppKey");
OR
string key = System.Configuration.ConfigurationManager.AppSettings["AppKey"];

I read somewhere in a Microsoft example where they imported
using System.Configuration;
and then use the standard
ConfigurationManager.AppSettings["MyKey"]
Just thought to post this in case somebody has the same question/problem

Related

Is it possible to use Ninject Named Bindings using ninject.extensions.xml

I have a very simple problem of DI, and wanted to know if there is a way to solve it using Ninject (or any other DI helper).
I have a Data Access interface that is implemented by several Data Sources providers, like DB, Sharepoint, CRM, etc.
I want to use Ninject to get a specific instance of the interface, based on a parameter that contains a code representing one of this implementations.
So far I know that I can do that by using named bindings , but I couldn't find a way to do the same by xml config file (Ninject.extensions.xml).
Ninject extensions xml provides a way to solve single mappings:
<module name="SomeModule">
<bind service="Game.IWeapon" to="Game.Sword"/>
<bind service="Game.IWarrior" toProvider="Game.SamuraiProvider"/>
</module>
I'd like to do a config like that, but using multiple mappings for the same interface, using a name, a code or the like.
TIA,
Milton
Just add a name property
<bind service="Game.IWeapon" to="Game.Sword" name="sword"/>
<bind service="Game.IWeapon" to="Game.Dagger" name="dagger"/>

How to do control binding in code for MonoDroid?

I am facing an issue with control binding in code in mono droid. I have an activity inheriting from MvxActivity and I saw some article to perform data binding in code using CreateBindingSet(). Can someone tell me what assembly reference I need on my monodroid project to get this method? If possible, can someone help me out with a sample example as well?
I am using V3 of MvvmCross.
Thanks
Amit
You need to have a using Cirrious.MvvmCross.Binding.BindingContext; and then you should be able to use Bind() on stuff.
Take a look at the DialogExamples Tutorial in the MvvmCross-Tutorial repository.
Binding is pretty simple, you need to create a binding set first:
var bSet = this.CreateBindingSet<TView, TViewModel>
Then you can use that to Bind UI objects:
bSet.Bind(myTextView)
.For(v => v.Text) //View Property
.To(vm => vm.Stuff) //ViewModel Property
There is also a lot more information on bindings in the Bindings Page in the Wiki.

XmlMediaTypeFormatter cannot write an object of type ObjectQuery

When using EntityFramework and returning an IQueryable from an MVC 4 Web API Get action, the following error occurs when the XML serializer is set to use the old XmlSerializer (rather than DataContractSerializer).
XmlMediaTypeFormatter cannot write an object of type ObjectQuery
Is this a known issue?
Too late for this question but for those who faced the same exception:
Your ObjectQuery class probably lacks a default constructor.
See my full answer here: Xml Serialization cannot write an object of type 'x'
No.
You need to define [Queryable] attribute on your action. This requirement was added on RC and probably will be removed at RTM
NOTE
OData support is very unclear at the moment. I have created PocoHttp for consuming ASP.NET Web API's OData but paused development because of lack of clarity at the moment.
I had this error because one of the members of the class I was serialising was an interface. I didn't need to serialise that member so annotating it with a [XmlIgnore] attribute fixed it.

EF 4.0 to EF 4.2 , DeleteObject Not Found,

My original project is in Asp.net MVC 2.
I convert my project to MVC 3 without problem.
In the same time, I install the EntityFramework 4.2. Again without problem.
Were it's begin to be complicated is when I add the T4 Generate DBContext.
Thats create me the T4 properly and generate all my entity into his own "POCO Class". Thats perfect!.
When I Build my project, I Got about 400 error. Here is some example.
'mvn.Models.DBEntities' does not contain a definition for
'AddToLeaseConditionInfos' and no extension method
'AddToLeaseConditionInfos' accepting a first argument of type
'mvn.Models.DBEntities' could be found (are you missing a using
directive or an assembly reference?)
As you can see here, the context.AddToLeaseConditionInfos(objCondition); doesn't work anymore.
Same for the DeleteObject context method.
context.ConvertionUnits.DeleteObject(MyObjConvertionUnit);
Someone has an Idea.
Thanks a lot.
You previously used ObjectContext API and default code generator (or EntityObject T4 template) but now you are trying to use DbContext API with POCO DbContext T4 Generator. Those two are completely incompatible because they represent different API. You must use the same code generation approach as you used in EFv4 (which means upgrade will not give you almost any additional value) or you must rewrite your current data access code to use new API.

Two classes have the same xml type name

When I try to publish my Workspace in RAD, I get this error "Two classes have the same xml type name", probably because the same class name exists in the same package, but in two different jars. And it seems like that the #XmlType annotation needs to have distinct values for its attributes name and namespace in the sources of these classes. I tried wsdl2java available in Apache CXF, but I'm not able to make it generate this namespace attribute. I tried fiddling with the -p package option, but that's only for placing the generated sources in the specified package.
Any ideas how to generate this namespace attribute for each element encountered in the wsdl? TIA.
thanks to Daniel's anwser:
CXF JAXB JAXBEncoderDecoder unmarshalling error : unexpected element when having qualified elements
i learned there is a parameter -xjc-npa for wsdl2java which helped me.
This will add XmlType.name and XmlType.namespace annotations to the generated classes so it won't be a problem if you have same class names but in different namespaces
I ran into this for an object named "SubmitDataResponse" that I was using as a return object from my web service method named "submitData". When I tried renaming the object, the error went away. It seems to me that CXF is creating its own return object based on the method name (in this case submitData() -> "SubmitDataResponse"). You may want to try renaming the class and see if you are having the same issue. Perhaps someone can chime in with a way to keep our class named the way we want them to (probably with some annotation).
I hope this helps.

Resources