This is a follow up to this problem.
That problem was fixed. However, new compiler errors occurred. The compiler errors indicate the following:
The Glimpse.Ado.AlternateType.GlimpseDbCommand class needs a default constructor
The Glimpse.Ado.AlternateType.GlimpseDbConnection class needs a constructor that takes a string (connectionString)
This second problem is strange, because the System.Common.DbConnection class does not have a constructor that takes a string either.
Related
After switching to LambdaModel as an alternative to PropertyModel in one of my forms in my Wicket 8 application I have failing submit tests stating:
java.lang.ClassCastException: java.lang.String cannot be cast to
java.math.BigDecimal
My Form Panel has a NumberTextField which in my working scenario is bound to a PropertyModel.
THIS WORKS
form.add(new NumberTextField<BigDecimal>("myBigDecimalField", new PropertyModel<>(getModel(), "myBigDecimalField")));
THIS DOES NOT WORK
form.add(new NumberTextField<BigDecimal>("myBigDecimalField", LambdaModel.of(getModel(), MyClass::getMyBigDecimalField, MyClass::setMyBigDecimalField)));
The problem is that LambdaModel does not implement IObjectClassAwareModel as PropertyModel does and so when the NumberTextField tries to resolve the type in AbstractTextComponent#152 and subsequentially checks in getModelType if the model is an instance of IObjectClassAwareModel it will not work, as LambdaModel does not implement this interface.
Is this intended that LamdaModel does not implmement IObjectClassAwareModel.
BTW I know that I can fix this issue with explicitly declaring the type class of the NumberTextField.
Regretfully it's quite hard to retrieve any type information from lambdas.
See here for an explanation:
Java: how to resolve generic type of lambda parameter?
So for now it's recommended to pass the type to the component.
My application parses settings using "typesafe.config" and then converts the Config object into an instance of a case class using "ficus". The case class currently has 19 constructor arguments. And everything works normally. However, when I add a new argument and a new corresponding field in my "settings.conf", I get the following exception:
An exception or error caused a run to abort: MyCaseClass.<init>(Ljava/lang/String;Lscala/Option;Lscala/Option;IZLscala/collection/Seq;Ljava/lang/String;ILscala/concurrent/duration/FiniteDuration;ZLscala/Option;Lscala/Option;ILscala/Option;Lscala/concurrent/duration/FiniteDuration;Ljava/lang/String;Ljava/lang/String;II)V
java.lang.NoSuchMethodError: MyCaseClass.<init>(Ljava/lang/String;Lscala/Option;Lscala/Option;IZLscala/collection/Seq;Ljava/lang/String;ILscala/concurrent/duration/FiniteDuration;ZLscala/Option;Lscala/Option;ILscala/Option;Lscala/concurrent/duration/FiniteDuration;Ljava/lang/String;Ljava/lang/String;II)V
I can see the "typesafe.config" is correctly parsing my new field into the Config object. But ficus then throws this exception. The new field and the new case class constructor argument have exactly the same name, as they should.
Any ideas why this may be happening?
The concrete problem is documented in the following commits:
1) https://github.com/ceilican/Scorex/commit/133157a6ad070cad7a57624c511ee917133ed5f1
2) https://github.com/ceilican/Scorex/commit/074e0bc5add3c666b0943497a5579f3fd365084d
3) https://github.com/ceilican/Scorex/commit/7c8d3475377a17b2a5383bf3a99d797650ca8bc3
The first two commits are working. With the third one, the exception mentioned above is thrown.
As you can see, there is not much conceptual difference between commits 2 and 3. I don't understand why commit 2 works, whereas commit 3 doesn't.
For a moment I thought it could be because of the large number of arguments in the case class, but the following commit shows that the problem also happens when I add the new field to a smaller case class:
4) https://github.com/ceilican/Scorex/commit/1c253b2b526db1539fa674069232cf02784c4bfb
The same kind of exception is thrown when I try to run the code after commit 4.
Is this a bug in Ficus?
After doing sbt clean on the main project and on subprojects, the problem stopped happening. My guess is that Ficus's macro magic generates functions based on my case classes, but they are not re-generated when the case classes are modified. Then, when Ficus tries to use the outdated functions that are incompatible with the new case classes, the exception is thrown.
Interestingly, the lack of re-generation happens only when I modify "nested" case classes. If the config file is:
main {
nested {
param: 0
}
}
with case classes:
case class MainCaseClass(nested: NestedCaseClass)
case class NestedCaseClass(param: Int)
Then, modifying MainCaseClass does not cause problems, but modifying NestedCaseClass does.
In a nutshell, if I define a constructor in a class thats named after the same name as the file itself, it returns the following area.
Some example code. Take the filename as ParseWebsiteData.scala for both.
This returns an error.
class ParseWebsiteData(url:String) {
}
This however, works fine.
class Foo(url:String) {
}
The only thing that I'm seeing as the issue are parser bugs from 2013, but this is the latest version of Eclipses's Scala IDE setup so I'm strongly thinking this is not the case, but turns out I'm wrong. Oops :(
As it's still an issue, what are the way(s) to avoid this occurring as I code in the future?
Well, can't tell the root cause but I was getting the same error in Scala Eclipse editor and I just did "project->clean" and it was gone!
Am facing an issue while trying to implement an example given over a website.
One of the methods in a class has a signature like this -
private void updateTable(JsArray prices) {....}
And am trying to invoke this method from another method as -
updateTable(JsonUtils.safeEval(response.getText()));
while doing this am seeing a compilation error as -
The method updateTable(JsArray) in the type StockWatcher is not applicable for the arguments (JavaScriptObject)
Though I have just used the exact code displayed in the website, am seeing this error. Not sure what needs to be done. Please help.
The problem has been fixed by making the following change -
updateTable((JsArray)JsonUtils.safeEval(response.getText()));
introduced a casting in the above statement.
Does anyone have a working example of sharprepository intergration with autofac using InstancePerApiRequest for DbContext?
I am registering my dbcontext thusly:
builder.RegisterType<AuditTestEntities>().As<DbContext>().InstancePerApiRequest();
If I remove the InstancePerApiRequest, sharprepository is able to get a dbcontext. But with the InstancePerApiRequest, I get the error message pasted below. Basically the crux of the error is, I suspect, the way sharprepository makes the call:
No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.
The full error stack:
iisexpress.exe Error: 0 : Operation=DefaultHttpControllerActivator.Create, Exception=System.InvalidOperationException: An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless public constructor. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor()' on type 'AccountRepository'. ---> Could not resolve type 'System.Data.Entity.DbContext' using the 'AutofacDependencyResolver'. Make sure you have configured your Ioc container for this type. View the InnerException for more details. (See inner exception for details.) ---> SharpRepository.Repository.Ioc.RepositoryDependencyResolverException: Could not resolve type 'System.Data.Entity.DbContext' using the 'AutofacDependencyResolver'. Make sure you have configured your Ioc container for this type. View the InnerException for more details. ---> Autofac.Core.DependencyResolutionException: No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.
Okay found the issue. There is a problem with using the SharpRepository AutofacDependencyResolver when using the MVC or Web API integration and trying to use the scope InstancePerApiRequest or InstancePerHttpRequest. Autofac expects those items to be resolved from the System.Web.DependencyResolver.Current instead of from the Autofac IContainer directly as the AutofacDependencyResolver is currently doing.
Here is how you can fix the issue right now until we make an overload for AutofacDependencyResolver that fixes the issue.
You will need to create your own dependency resolver within your project like this one:
public class CustomAutofacDependencyResolver : BaseRepositoryDependencyResolver
{
private readonly IDependencyResolver _resolver;
public CustomAutofacDependencyResolver(IDependencyResolver resolver)
{
_resolver = resolver;
}
protected override T ResolveInstance<T>()
{
return _resolver.GetService<T>();
}
protected override object ResolveInstance(Type type)
{
return _resolver.GetService(type);
}
}
And then register it with SharpRepository so it will use it to resolve the DbContext and then it will work as expected.
RepositoryDependencyResolver.SetDependencyResolver(new CustomAutofacDependencyResolver(DependencyResolver.Current));
** Update**
I was testing with MVC and able to replicate the error and fix it but that doesn't work with Web API. I am used to using StructureMap where it works fine using the GlobalConfiguration.Configuration.DependencyResolver.
It seems the issue is that Autofac needs a IDependencyScope that you can access from the HttpRequestMessage but I'm not seeing a way to get to that outside of the ApiController. This describes the issue and the reason: https://groups.google.com/forum/#!msg/autofac/b3HCmNE_S2M/oMmwFE5uD80J
Unfortunately right now I'm at a bit of a loss on the best way to handle this. But I'll keep thinking about it.
So, I was able to get mine working by changing the lifetime scope to InstancePerLifetimeScope. I don't know whether this has any unforeseen consequences or not. Everything appears to be working fine for me so far.