Can you set up a service to use ngResource in Angular, or does it have to be a factory? - ngresource

In almost every tutorial I've seen on using ngResource in Angular JS I see them set up the $resource as part of a factory. My question is can this also be set up as a service as well that could be injected into the controller? I just wanted to clarify that before I start writing any code on it. Thanks!

Related

Spring Boot, do I even need a model with vuejs?

I'm having trouble understanding and then deciding how I want setup the frontend of my spring boot application. My question is do I even need thymeleaf or rather do I lose something if I only use vuejs?
First things first I am mostly into backend stuff and barely know a lot about current frontend technologies etc. However I tried out vuejs and liked it a lot.
I used to use thymeleaf and serve static html pages with thymeleaf markup. After playing around a bit with vuejs I want to use that instead.
So far I've managed to set it up two ways:
I keep thymeleaf and use it together with vuejs. This allows me to keep the model that I can pass in my view controllers.
I only use vuejs and get all information through REST from the spring boot app. However I am asking myself if there isnt a way to access the model from here? If that would be the case I wouldnt need thymeleaf right?
I really think that I'm having some kind of architectural misunderstanding and would appreciate it if I could get it cleared up.
Thank you in advance

How to use Autofac to initialize your own components?

I would like to use Autofac IOC container in my bot application (based on BotFramework).
I can see that framework itself already uses it.
But I can't figure out how to do it gracefully... I don't want to resolve my components on every post invocation (it will slow down my post method execution).
I appreciate if you share code snippets with your solutions.
Thanks in advance!
You can use the Autofac container being used in the framework in the Global.asax and perform your own registrations.
The key code pieces are:
var builder = new ContainerBuilder();
// perform your registrations on the builder
// update the container being used by the framework
builder.Update(Conversation.Container);
For a real implementation of this, you could take a look to the ContosoFlowers sample where you will see that a Module is used to register the application specific components. Here is the Global.asax and here the actual module.

Spring Web MVC and recurring dynamic page elements

I'm new to java and web apps and after trying out a few things I went with a set up of Spring webmvc using annotations and velocity as templating engine. It's not that hard to do simple #RequestMapping annotations to controller methods and returning ModelAndView instances filled with data, however I was wondering how things are done when you have data you need in the model that occurs on every page, for example "latest 5 news items" or something similar. You could of course always fill the model with such data in every method that is handled by a #RequestMapping, but I'm quite sure that that is not the way to do it.
What is the correct way of filling the model with recurring data, without poluting your controller methods with calls to the same method for this recurring data.
Any help is appreciated.
You could use a servlet filter or a Spring interceptor, and get the recurring data from this filter or interceptor and place it in a request attribute.
Another solution is to let the page call more than one controller, for example by using multiple ajax requests. Then one controller could is responsible for the specific page and another is responsible for "latest 5 news items", see related question.
Good question dude. In my current app i am using sessions to store my username which is appearing on all the rest of the app.
#JB Nizet thanks for the link.. now ill go for spring interceptor

Is it ok to call SignalR's IConnectionManager inside my mvc3 controllers?

I'm on an MVC3 project and I am using snap structuremap for my dependecy injection. Everything was in-place, except when I started using SignalR where I can't seem to implement my DI like I have on my controllers. I've been googling about implementing structuremap DI on SignalR for days now, but haven't found a strong sample on how to do this. Seems like everyone that are using SignalR are using Ninject.
My goal is to have conditional statements (which requires me to inject services) inside my Hub before calling my client methods, but I had no success on this.
I didn't want this thing to delay my development so I researched for alternative ways, then I found out that I can actually call my client methods from my controllers using the following codes:
IConnectionManager connectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>();
dynamic clients = connectionManager.GetClients<MyHub>();
clients.myClientScript();
This works for me, but I'm not sure if this is a good approach - especially that I am using dependency injection.
So my question is: Is it ok to keep calling this inside my controller? Do you have a better approach?
Thanks
There is no reason you cannot send information to connected clients from your controller using SignalR however the current client will not see this information (due to not being connected during a post).
That said, getting Structuremap into SignalR is actually pretty easy. You can see exactly how to accomplish this in my answer here: https://stackoverflow.com/a/9866374/701062.

DOJO with spring framework

I am new to Spring as well as Dojo. I need to use Dojo with one of my mvc project in Spring 3.0
I came accross below link which talks about using spring-js with Dojo.spring-js part of spring framework?
http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch11.html
I could not really follow that link, is there any step by step tutorial which will show me how to use dojo with spring framework 3.0 ?
I need to start with simple things with Dojo like client side validation of forms.
Thanks in advance!
This is a tough question to answer, because it turns out you don't really need to worry about how Dojo and Spring interact. Your client and your back end server are completely unrelated until you decide to send data back & forth.
So for dojo, you probably want to look at how to use some of the form validation. Take a look at this link for some help on that:
http://o.dojotoolkit.org/book/dojo-book-0-9/part-2-dijit/form-validation-specialized-input
Once you have some validation in place, your form can use the normal form post to post your data to the server, same as how you would do it without javascript.
On the other hand, if you want to add some nice Ajax to your application, take a look at this link which explains how to implement Jackson marshalling/unmarshalling to send JSON data to Spring & handle responses correctly.
http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/
Spring Roo uses Dojo, so you can create a Roo Project and have a look like they did it.
For Spring, You can follow this tutorial (Its the most compact and covers all basics):
http://www.tutorialspoint.com/spring/index.htm
And for Dojo The best tutorial is at: http://dojotoolkit.org/features/desktop
(in Create Beautiful User Interfaces subheading youll find all the APIs and their examples)
Its the way I learnt it. :)
Cheers

Resources