Unity resolving unmapped types with null - unity-container

If I don't have the concrete class mapped to the interface, when Unity tries to resolve the type it gives me this error: "The current type, IFoo, is an interface and cannot be constructed. Are you missing a type mapping?".
However, for testing purposes, I'd like Unity to pass null to the interfaces that aren't mapped yet to concrete types.
Any suggestion to make this as the default behavior to "resolve" unmapped interfaces?
Thanks

I could let Unity pass null to my dependencies using the OptionalParameter while configuring the constructor injection.
container.RegisterType<IObject, MyObject>(
new InjectionConstructor(
new OptionalParameter<IFoo>()
)
);

Related

runtime constructor parameter using microsoft DI

How can I pass runtime constructor parameter to resolve an object while using Microsoft Dependency Injection.
All that looks possible is to pass the parameter only in the startup while adding the object to the DI.
In Autofac, this is possible but nothing available for Microsoft DI:
var reader = scope.Resolve<ConfigReader>(
new NamedParameter("configSectionName", "sectionName"));

Resolution failed with error: No public constructor is available

I am using WCF web services and it was using OLD unity 2.0. So i updated Unity and other reference with latest version 5.0. I am getting exception:
Resolution failed with error: No public constructor is available for type xyz.Services.Contracts.Security.IAuthenticationService.
For more detailed information run Unity in debug mode: new UnityContainer().AddExtension(new Diagnostic())
Exception of type 'Unity.Exceptions.InvalidRegistrationException' was thrown.
Really i tried many things but not success. please any expert have a look.
I came across the same error upgrading from Unity version 3.5 to 5.11. In my case, during resolution the exception was the same ResolutionFailedException with message "No public constructor is available for IMyInterface" and having the same inner exception InvalidRegistrationException.
Well, the error messages and types of exceptions were misleading in my case; there was no registration problem nor did I ask for a public constructor for the interface. It seems that there has been a breaking change in the Resolve method overload which takes an instance name. Null names are no longer equivalent to empty string names. Replace your empty string name to null or use the other overload which doesn't specify an instance name:
var service = container.Resolve<xyz.Services.Contracts.Security.IAuthenticationService>();
OR
var service = container.Resolve<xyz.Services.Contracts.Security.IAuthenticationService>(null);

How is symfony normalizer instantiated?

I'm looking at a symfony project that is declaring a custom normalizer. It has an optional argument in the constructor which is getting ignored.
public function __construct(SomeInterface $firstArg, $secondArg = false)
{
//$secondArg is always false
}
There is some yml config:
Path/To/Custom/Normalizer:
arguments:
$secondArg: true
tags: [serializer.normalizer]
I'm trying to understand what is instantiating this class, and why is the second argument always false, despite the fact that the yml config defines it as true.
Is the normalizer instantiated using the yml config, or does symfony instantiate these using some other mechanism?
More info:
if i make the second constructor arg mandatory, then the container wont compile. complaining that it can't autowire the second arg and that i must configure its value explicitly. Which is what i am trying to do.
Autowiring of symfony doesn't know how to autowire scalar parameters type.
Your manual configuration will never be execute if you enable autowiring for this service.. So the container tries to create new instance of your service but he doesn't know how to instantiate the boolean parameters.
What you can to is to exclude this service from the autowiring
It is a bad idea and can become quickly a very big headache to have different default value on constructor and the service configuration itself.
The order in which the bundles are loaded, defined in AppKernel.php makes a difference to the configuration.
Even though there does not seem to be any other configuration of this class in any other bundle.

How can I get an Alfresco ContentService object?

I am attempting to read the content of a file in Alfresco. I have seen examples that use
ContentService. Unforunately, when I try to use the example code, the ContentService
is not available.
I have added ContentService as a managed property of my managed bean in faces-config.xml
<managed-property>
<property-name>contentService</property-name>
<value>#{ContentService}</value>
</managed-property>
In my java code, I am using
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
// contentService is an instance variable.
this.contentService = serviceRegistry.getContentService();
I am getting this Exception:
javax.faces.el.EvaluationException: Exception while invoking expression #{DeployAssetQADialog.start}
caused by:
javax.faces.el.PropertyNotFoundException: Bean: com.XXXXXXXXXX.CCCCCCCC.DeployAssetDialog, property: contentService
Can anyone tell me if there is something that I am missing? Thanks
PropertyNotFoundException sounds like your managed bean is missing a setter method.
How to expose spring managed beans to jsf may depend on the spring and/or jsf version you are using. Have a look at Spring beans injected into JSF Managed Beans for an example.
Finally, Make sure your Alfresco spring context is initialized before jsf kicks in.
Many issues in code
1) For each services which are injected you need to add getter setter method for them.
If you add getter setter for contentservice you can get rid of your error.
2) Other thing is you are trying to get conentservice though service registry in that case you need to inject service registry and add getter setter for that. Otherwise get contentservice instance directly as it is injected though faces-config and provided you have added getter setter for it you can directly use that instance of contentservice.

Flash Builder Localhost works 100% Remote Host just shows title of Object for every entry

I have finally gotten my Flash Builder to look at my remote services but now I have a problem that my Remote information, which should be the same except for alot more entries, just displays each object with the title [object Object] I have had a look around and I see if I test the service out locally, it is working as it calls all the information under Response Name 'object and Response Value 'Object'
On my localhost configuration this shows the name which is inside my Object items. How can I fix this?
[object Object] is the result of the toString() method of Object. If you get this it probably means your custom object type is being returned as a generic object from the remote AMF service. A lot of things could be the cause of this. Here are a few to check:
1) Make sure that your custom object type is compiled into the app. IF the object is never used explicitly the Flex compiler will not put it in the final SWF. You can do this by creating a fake variable:
private var myUnusedObject : MyCustomObjectType;
Or, I believe, there is a compiler flag to force unused classes to be compiled into the SWF.
2) You may have to add a formal mapping on your server. This depends primarily on what server side tech you're using. In AS3 you add a RemoteAlias metadata to the class. In ColdFusion you use the alias tag on the cfcomponent tag. I believe in WerbORB.NET I had to add the mapping in an XML Config file [but it's been years since I've done that]. I assume alternate technologies use similar approaches.
3) Check case sensitivity on the path names for your server code and make sure that the aliases (mentioned in 2) match.
4) In ColdFusion AMF you have to make sure that your public properties and types match up. They must be in the same order in your AS3 class as they are in your remote CFC. The property types must match. String to String; Boolean to Boolean, etc... I assume other AMF implementations have similar restrictions.

Resources