Autofac XML/JSON Configuration for Generic Type of Repository Pattern - autofac

I have a class BaseRepository which implements IRepository.
How would I specify it on the JSON configuration file, to register the generic types?

Autofac configuration (XML/JSON) doesn't support registering open generics.
Instead, create an Autofac module that does the open generic registration and set that up in your configuration.

Related

Resolve binding without instatiating object in Ninject

I have interface (e.g. IMyInterface). I need to get of which type object will be created if I call kernel.Get<IMyInterface>(). Not the instance of IMyInterface but the type of instance without creating instance itself. Is it possible?
Ninject doesn't have this functionality. From a Ninject IKernel (like StandardKernel) you can call GetBindings(Type) but Ninject uses a provider model, so the binding's provider has to be invoked to view the result.
I would suggest creating a custom meta-service to mappings of services to implementations, if this functionality really needs to be dynamic.

Play Framework 2.4.1: How to migrate custom plugins

As of Play 2.4 the Plugin class is deprecated and one should use the Module class instead.
I've understood file play.plugins is no longer necessary and custom modules should be registered in application.conf as documented here.
But how do I migrate my old plugins? The Module class doesn't contain methods onStart and onStop... Is there an example somewhere?
This pull request has the full Redis plugin migration from 2.3 to 2.4. They use the constructor for the onStart and ApplicationLifecycle for the onStop in SedisPoolProvider.
https://github.com/typesafehub/play-plugins/pull/148/files
Documentation explains that the goal is to provide bindings in a DI framework agnostic way. This is the reason I believe there is no trait with onStart and onStop to implement. The agnostic way is to use constructor and/or by injecting a lifecycle module like ApplicationLifecycle.

How to handle/create new content-type/MediaType in JAX-RS?

I am researching on Jersey and RESTEasy. Media-type negotiation for XML and JSON works fine, and I am able to consume and produce both of them. However, I am being asked to produce and consume a response for a new content-type. For instance, BSON, or a self customized content-type. I googled online but could not find much information in it. Is there anyway, I could still use the #Produces and #Consumes annotation in JAX-RS for the new content-type?
Thanks in advance.
Yes, you can use #Produces and #Consumes with custom media types. In order to use the custom media type when marshalling and unmarshalling content you need to create MessageBodyWriter and MessageBodyReader implementations to handle the media type.
Here is how to implement a custom media type:
Annotate your resource methods with #Consumes({"application/mycustomtype}) and #Produces({"application/mycustomtype}) as required.
Implement custom MessageBodyReader and MessageBodyWriter implementations to support your custom media type.
Annotate your MessageBodyReader with #Provider and #Consumes({"application/mycustomtype})
Annotate your MessageBodyWriter with #Provider and
#Produces({"application/mycustomtype})

Caliburn.Micro. Automatically call eventaggregator.Subscribe() for IHandle implementors with MEF

In Caliburn.Micro documentation the authors mention such possibility:
documentation link
IHandle inherits from a marker interface IHandle. This allows the use of casting to determine if an object instance subscribes to any events. This enables simple auto-subscribing if you integrate with an IoC container. Most IoC containers (including the SimpleContainer) provide a hook for being called when a new instance is created. Simply wire for your container’s callback, inspect the instance being created to see if it implement IHandle, and if it does, call Subscribe on the event aggregator.
How is it possible to achieve this with MEF?
This question is the same as Caliburn.Micro. Automatically call eventaggregator.Subscribe() for IHandle implementors with Autofac
So how is similar functionality as the described AutoSubscribeHandersModule implemented in MEF?
I blogged about how to do the auto-wiring for the Event Aggregator with MEF in Caliburn Micro here;
http://www.kjetilk.com/2011/10/auto-wiring-eventaggregator.html.
In short; You need to add the MEFContrib (nuget -> Install-Package MefContrib), implement an IExportedValueInterceptor that subscribes any IHandle instances, and plug the interceptor into the MEF creation pipeline using an InterceptionCatalog in the bootstrapper.
Check MEFContrib's InterceptingCatalog. Just put IHandle instead of IStartable as described in the referenced article.

Use pojo as gwt RequestFactory proxy instead of interface

Is there any easy way to use a pojo as a request factory proxy and not an interface? The case is that I would like to reuse the actual value object as is without creating an interface describing it.
I do not that this can not be done out of the box. GWT fails to compile with an error regarding non getter/setter methods insite the "proxy" class.
This not possible, by design. See this previous StackOverflow answer.