Implement LightInject WCF into a WCF web Service - light-inject

I am trying to implement LightInject into my WCF service.
I have the LightInject.Wcf class file from GitHub but i have no clue on how to use it in my service.
Please help

I just run into the same problem. I had already noticed the post you are referring to, but i assumed there must be an easier way. By inspecting the code i found an alternative:
Make sure you get the latest version of LightInject.Web and LightInject.Wcf. Just as a regular MVC application you can setup things in the global.asax:
protected void Application_Start(object sender, EventArgs e)
{
var container = new ServiceContainer();
container.Register<ILogger, Log4netLogger>();
container.EnableWcf();
}
After this, configure the services as you would normally do without LightInject.

I have found this after lots of searching
http://www.ienablemuch.com/2014/10/wcf-lightinject-nhibernate-part-1-of-2.html
a step by step guide to setting this up, which is what I was after.

Related

Enabling EJB Injection into Vaadin 7 UI via Usage of Vaadin-CDI-Integration Addon

I wasn't able to successfully integrate the official Vaadin-CDI-Integration-Addon, since after finishing the official integration instructions, the following Exception was thrown in case I reloaded the already published URL localhost:8080/App/?restartApplication.
javax.servlet.ServletException: com.vaadin.server.ServiceException:
java.lang.IllegalStateException: UI id has already been defined
The following little workaround is a tested, working solution, which completes the official instructions.
You have to work off the following steps to successfully integrate the official CDI-Integration-Addon into your Vaadin project.
Do exactly as stated in the official how-to.
Remove the ?restartApplication parameter from the URL. This avoids the Exception.
Inject the EJB as shown in the listing below.
Keep in mind to restart your application manually if necessary!
#CDIUI
public class ExampleCDIUI extends UI {
#Inject
MyLocalBeanInterface myBean;
#Override
public void init(VaadinRequest request) {
Label label = new Label("Hello Vaadin user");
setContent(label);
// myBean should be accessible now.
}
}
That's it. I hope this helps :-)

Create a GWT RPC Service

I’m trying to create a backend for a homepage with GWT. I created a Google Web Application in Eclipse without sample code and now I would like to add the service, but the developer Google guide doesn’t help me. I’m not sure, where to add the interface and how it exactly works.
If I understand the google documentation correctly, I have to add a module and an entry point class, is that correct? It would be great if you could give me some tips and help how to create a rpc service.
If you create a new GWT project in the Eclipse "New Project" wizard, with "Generate project sample code" checked, it will include a fully functioning RPC service with a sample method, which you can then adapt or copy according to your needs.
Out of memory, don't have eclipse in front of me.
First do create a test project with generated testcode, you can delete it afterward.
Yes you will have to add a module.
Create in client the two interfaces for the async calls, inherit it on server side.
Hope I understood your question right.
I'm not sure what would help you the most. Google developer guide was enough for me (at least when I started using it on version 1.6) to create RPC services for my GWT application.
General APP
Module: is the .gwt.xml file. Yes, you'll need it. The GWT compiler will find it automagically and try to compile all the GWT code (the <source> element will tell which subpackage contains Java code that will be converted to JS). It will tell also which class implements the EntryPoint interface. The onModuleLoad will be the code executed when javascript runs in the client page.
RPC
Well, you should first try UI things and only then, when you're confident enough, try the server thing. Anyway the scheme is:
interface MyService extends RemoteService {
List<String> doSomething(String sample, int other);
}
#RemoteServiceRelativePath("../path/to/servlet") // see later
intercace MyServiceAsync {
void doSomething(String sample, int other, AsyncCallback<List<String>> callback);
}
These are the interfaces. Later is the async one. That's what you'll use from client side. Always calling and passing an implementation of AsyncCallback which will receive (sometime later, you don't know when) the result.
First interface is the syncrhonous one. That is what you need to implement on server. You must inherit from RemoteServiceServlet class (it is an implementation of servlet that already does all the values handling), and implement your interface. GWT code does the rest (almost).
public class ServiceImpl extends RemoteServiceServlet implements MyService
{
// implement the method normally
}
From client you'll need to create the service proxy:
private static MyServiceAsync MY_SERVICE = GWT.create(MyService.class);
Yes. I know it's weird how GWT knows MyserviceAsync and MyService work together. Don't worry about that. It works :)
Just use the service like this:
MY_SERVICE.doSomething("value", 111, new AsyncCallback<List<String>>() {
// note that this code executes some time in the future when response from server is back
public void onSuccess(List<String> result) {
Window.alert("Server answered with " + result.size() + " elements!");
}
public void onFailure(Throwable t) {
Window.alert("Server failed: " + t.getMessage());
}
}
Path to server
You'll have to configure your app to make that servlet implementation listen to URL indicated in #RemoteServiceRelativePath. That's the way client knows where to make the request, and the server knows which servlet attends that request. I'd suggest using:
../my-service.gwt as relative path (GWT module gets published in <ROOT>/module_name
and
configuring your web app to use the servlet for /my-service.gwt
But it's entirely upon your preferences :)
Anyway I think Google tutorials are the best. So please copy&paste. Try&modify until you get to understand the whole thing.

Creating window.postMessage() in GWT for cross-domain iframe messaging

I am trying to communicate between parent window and IFrame(IFrame source being on different domain), which is not allowed directly since the Same Origin Policy. The communication is easy via window.postMessage() method of HTML5. So i searched for existing works in this field and i found gwt-rpc-plus library
It includes a class PostMessageFrameTransportRequest. Now, I think that this would work. But I am not getting on how to use this class.
I need some help with this code and if anyone knows about some other method to give same behavior as window.postMessage() please help me out.
Thanks in advance....
You can just use JSNI to call javascript directly
something like:
private native void sendMessage(String message)/*-{
$wnd.postMessage(...., message);
}-*/;

RegisterType<> Not visible on Silverlight

I was following an example found here on StackOverflow, and everything went well until I need to register my types.
My web application is running on Silverlight 4, with Prism and MVVM.
The example is using "Microsoft.Practices.Unity" (it's a windows form application)
Bootstrapper.cs
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterType<IApplicationMenuRegistry, MenuRegistry>();
Container.RegisterType<IApplicationCommands, ApplicationCommands>();
Container.RegisterType<ShellViewModel, ShellViewModel>(new Microsoft.Practices.Unity.ContainerControlledLifetimeManager());
}
Mine is using: Microsoft.Practices.Unity.Silverlight (web) and throws the following error:
The non-generic method 'Microsoft.Practices.Unity.IUnityContainer.RegisterType(...) cannot be used with type arguments.
And the RegisterType<> constructor is not visible for me. Which alternatives do I have to register my types?
I am using Unity for Silverlight and have not had this issue.
According to this post, http://unity.codeplex.com/workitem/8205, you need to add "using Microsoft.Practices.Unity;" to the file. The generic versions of Resolve are extension methods and you need to pull in the namespace to use them.
Apparently ReSharper may think the using statement is not needed and may remove it.
Hope that helps.

Manage autofac container setup

One of my team members decided to use autofac on one of our services and because we wanted to try it out we stuck with it.
Now some time has passed and the container setup method has grown! It so big that we are having problems with it.
Splitting it up did not bring the results we looked for. Maybe we are just using it wrong.
So my question is: How can we manage the container setup? Can we dump into XML or are there any other best practices?
There are many ways to manage container setup with autofac.
One of the most common ways is to use a Module and register it with the builder. You can break up multiple groups of registration this way:
public class DALModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register<SomeDataSomething>().As<IDataSomething>();
builder.Register<SomeOtherSomething( c => SomeOtherSomething.Create());
//and so on
}
}
Then register these broken up modules with the builder either via code or XML.
(a simple call to builder.RegisterModule( new DALModule()) would do it here). See the wiki page on Structuring with Modules.
Or, you can use only XML files (or use XML and modules together). See the wiki page on XML config for this.