Constructor list/array type parameters in the XML configuration - autofac

How can I pass an array/list parameter to the class constructor using the XML configuration?
If I want to pass a scalar value I use following configuration:
<components name="0">
<type>XXX, XXX</type>
<services name="0" type="XXX, XXX" key="YYY"/>
<injectProperties>true</injectProperties>
<instanceScope>single-instance</instanceScope>
<parameters>
<param1name>param1value</param1name>
<param2name>param2value</param2name>
</parameters>
</components>
The constructor of my class expects a parameter of the IEnumerable type .
Best regards,
arnam

Short version: That's not currently supported. Related issue here.

I've tried with a JSON config but parameters arn't passed to the constructor. My config looks like that:
"parameters":{
"constructorParamName":["stringValue1", "stringValue2"]
}
and the constructor is:
public MyClassConstructor(IList<string> constructorParamName = null)
Unfortunately "constructorParamName" value is always null.
Update:
I figured out that problem is caused by IContainer.ResolveNamed method. This method passes properties from a config file but doesn't passes constructor parameters.

Related

How to set arrays of string to #EnableJpaRepositories from property files

I have a jpa configuration file with #EnableJpaRepositories annotaion. I set this annotaion value from application.properties file like this :
#EnableJpaRepositories("${jpa.repository.packages}")
public class JPAConfiguration {
....
}
and here is my application.properties file:
jpa.repository.packages=com.epms.model
and it works perfect. but i want to specify multiple packages for #EnableJpaRepositories . so i changed my config file to this :
jpa.repository.packages=com.epms.model,com.ecms.model
and also configuration file to this :
#EnableJpaRepositories("#{'${jpa.repository.packages}'.split(',')}")
public class JPAConfiguration {
}
but it's not working . any idea ? how can i do this in my configuration file?
As #amicoderozer is asking, if your classes share a common base package you only must indicate that root package.
If it's not your case (despite you are loading from a config file or you are declaring them manually) maybe the problem (will help posting any Exception or Runtime trace) is the way the split method is used. It returns an array, and I guess the generated code will be like this:
#EnableJpaRepositories("jpa.repository.packages1","jpa.repository.packages2")
That code doesn't compile.
Never tried Spring EL inside the annotation of a component, but despite this, maybe you should indicate the basePackages this way:
#EnableJpaRepositories(basePackages = "#{'${jpa.repository.packages}'.split(',')}")
If doesn't work, I recomend you first test it by manual array declaration:
#EnableJpaRepositories(basePackages = { "com.epms.model","com.ecms.model" })
Be sure all works as you expect, and then try again reading and parsing from config file.
UPDATE:
After some readings, I've concluded that is not possible do what you want. The SpEL is allowed in many places but for annotations there is only documentation and working examples with #Value annotation.

Property Mapping Exception in Helhum upload example

I am using helhum File Upload Demo to upload the images. But currently i got below error.
Exception while property mapping at property path "images.0":Property "name" was not found in target object of type "XXXX\XXXXX\Domain\Model\FileReference
Please help here.. How can i move forward.
Thanks in advace.
If you followed the example extension, you are maybe missing the registration of UploadedFileReferenceConverter and ObjectStorageConverter in your ext_localconf.php. Took me a day to find that one:
ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerTypeConverter('Vendor\\EXT\\Property\\TypeConverter\\UploadedFileReferenceConverter');
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerTypeConverter('Vendor\\EXT\\Property\\TypeConverter\\ObjectStorageConverter');
In the initializeUpdateAction (or initializeCreateAction) you have to use the name of the parameter in the updateAction (or createAction) as argument.
If your updateAction looks like this:
public function updateAction(\Classname $yourObject)
You have to call the helhum function with the argument:
$this->setTypeConverterConfigurationForImageUpload('yourObject');
As a small hint for later problems: In the setTypeConverterConfigurationForImageUpload function you should register your own file attributes if they are not named image and/or imageCollection.0 like in the example.

MyBatis does not resolve Inner class when parsing SQL Mapper Configuration handlers

Using MyBatis 3.2.8, I'm trying to map an enum type (Status) to the jdbc VARCHAR type (to can use only the enum in my entity bean). So I defined the TypeHandler UserStatusHandler
import com.sample.User.Status;
import org.apache.ibatis.type.EnumTypeHandler;
public class UserStatusHandler extends EnumTypeHandler<Status>
{
public UserStatusHandler(Class<Status> type)
{
super(type);
}
}
I correctly declared the handler in the xml config file and in the UserDao.xml (mapping the attribute Status to the VARCHAR in the resultMap ...)
sample :
In the XML config file:
<typeHandlers>
<typeHandler handler="com.sample.dao.UserStatusHandler" javaType="com.sample.User.Status"/>
</typeHandlers>
In the DAO mapper XML file:
<resultMap id="UserResultMap" type="User">
<id property="id" column="ID" javaType="long"/>
<result property="status" column="STATUS" typeHandler="com.sample.dao.UserStatusHandler" javaType="com.sample.User.Status"/>
xxxxx
</resultMap>
But the problem incoming from MyBatis was that MyBatis cannot found my java enum class because it is defined inside another interface
public interface User
{
public enum Status
{
A, B, C
}
...
}
When I define this enum class in a separate file, it works with no problem, but I don't like to change my design (because of a limit ? ), I search to understand why MyBatis cannot found the class in this case ? Is it a way to fix this ?
MyBatis cannot build the SqlSession. While executing a simple test to find a User I get the following exception
Cause: org.apache.ibatis.builder.BuilderException:
Error parsing SQL Mapper Configuration. Cause:
org.apache.ibatis.builder.BuilderException: Error resolving class.
Cause: org.apache.ibatis.type.TypeException: Could not resolve type
alias 'com.sample.User.Status'.
Cause: java.lang.ClassNotFoundException: Cannot find class:
com.sample.User.Status
Finally I solved it by writing, in the XML configuration file, the name of the Inner enum like its associated compiled file name in the jar i.e. by adding a dollar $ between the enveloped and the inner class.
com.sample.User$Status
It appears a bug or a limit in MyBatis ..

GWT how to set gwt.imageResource.maxBundleSize? (or any System Property's to Integer)

I need to change the system property
gwt.imageResource.maxBundleSize
to 1000.
How would I do this?
The property exists as I see it here;
https://code.google.com/p/google-web-toolkit/source/browse/releases/2.5/user/src/com/google/gwt/resources/rg/ImageBundleBuilder.java#471
Yet I cant figure out how to set this in the GWT.XML:
<set-property name="gwt.imageResource.maxBundleSize" value="1000" />
results in;
[ERROR] Property 'gwt.imageResource.maxBundleSize' not found
so I tried creating the property;
<define-property name="gwt.imageResource.maxBundleSize" values="1000" />
but that gets me;
[ERROR] Invalid property value '1000'
In fact, any numerical values results in this error. The only things it accepts are strings starting with letters.....but thats obviously useless as Googles code is;
private static final int IMAGE_MAX_SIZE = Integer.getInteger(
"gwt.imageResource.maxBundleSize", 256);
So I am stumped how I am supposed to set this property.
<define-property name="gwt.imageResource.maxBundleSize" values="1000" />
You are creating a new property here, not assigning a value to an existing property. I don't know why the error is happening, but rest assured that even if the error wasn't happening, you'd still not be setting the value you are trying to set. Because...
private static final int IMAGE_MAX_SIZE = Integer.getInteger(
"gwt.imageResource.maxBundleSize", 256);
that code doesn't read from your gwt.xml file. From the javadoc for Integer.getInteger:
/**
* Determines the integer value of the system property with the
* specified name.
According to this, you should be setting a system property when you run the compiler (or dev mode). Adding this to the JVM args might look something like this:
-Dgwt.imageResource.maxBundleSize=1000

ExecuteSprocAccessor with Refcursor in EnterpriseLibrary 6.0 DAAB

I am using VS2012, EnterpriseLibrary 6.0 [DAAB]. My connectivity to the Database [Oracle] is fine.
I have a Oracle procedure, which does not have any input parameter only the output parameter is there, which is of type RefCursor.
I am able to get the output by calling the procedure using Execute Reader and ExecuteDataset.
Now I am trying to use DatabaseExtension.ExecuteSprocAccessor. I am getting the error, which says invalid type of argument.
Can any one provide me a good example for using the ExecuteSprocAccessor.
Thanks
//GREAT NEWS //
I found the ROOT CAUSE of the issue and it is in the Enterprise Library 6.0, DataBlock source code in the class CommandAccessor.cs at Line no. 66.
Because inside the command object, the parameter collections are not there. To resolve this, we need to do the following in the SprocAccessor.cs, [The method is in Line no.97]
In the below method, the command object was inside the using statement. Due to that, the command looses it is parameter collection values when it is outside the scope of the using clause. So, I have removed the using clause and it is working fine.
/// <summary>
/// Executes the stored procedure and returns an enumerable of <typeparamref name="TResult"/>.
/// The enumerable returned by this method uses deferred loading to return the results.
/// </summary>
/// <param name="parameterValues">Values that will be interpret by an <see cref="IParameterMapper"/> and function as parameters to the stored procedure.</param>
/// <returns>An enumerable of <typeparamref name="TResult"/>.</returns>
public override IEnumerable<TResult> Execute(params object[] parameterValues)
{
/*
using (DbCommand command = Database.GetStoredProcCommand(procedureName))
{
parameterMapper.AssignParameters(command, parameterValues);
return base.Execute(command);
}
*/
DbCommand command = Database.GetStoredProcCommand(procedureName);
parameterMapper.AssignParameters(command, parameterValues);
return base.Execute(command);
}
I am now very happy, to find the root cause. It is now working fine. Output is coming like a bullet.
Thanks