How can I get a log showing which instances the nested container of Structuremap is disposing?
Just to help the people who will stumble upon this, here is an answer from the man Jermey himself. He answered the question on his blog here.
You could go run thru the IContainer.Model structure and figure out what has been created as an IDisposable transient during the nested container. Not really something I anticipated here.
Related
I am new to vaadin and JPA containers.
I've read both tutorials here:
https://vaadin.com/book/-/page/jpacontainer.usage.html
and here:
https://vaadin.com/download/jpacontainer-tutorial/#__RefHeading__3056_1659804707
And neither makes sense to me.
Can anyone out there break this stuff down for me in layman's terms:
This is how you make a container.
Then you put this grid in the container.
Then the container is sent to the database like this.
If we can start with one simple CRUD grid that saves someone's name, for example, I think I would be able to build off of that.
But these tutorials bring in so many new classes, terms, and methods at once, I can't make any sense of it.
Thanks in advance!
If you want to use JPA with Vaadin, there are much better ways to do that than to use JPAContainer. Build a facade (e.g. an EJB) like you would do with other Java apps and bind the entities and basic lists of entities with Vaadin components.
See my rant about this for more details.
I have a large application which uses the old way of getting instances using ObjectFactory.GetInstance().
Now I want to move to application to the more correct way of injecting dependencies using constructor injection. However, it is almost impossible to convert all code at once (some static classes use ObjectFactory.GetInstance, other services do not have constructors with all dependencies, ...).
I was wondering if there is a way of replacing ObjectFactory.GetInstance calls with an replacement that uses the current nested container, e.g. replacing all ObjectFactory.GetInstance with Ioc.GetCurrentNestedContainer().GetInstance, to get it quickly up an running.
But how would I could I implement Ioc.GetCurrentNestedContainer to return the currently active nested container?
I can not inject IContainer in all these classes (some are static or have no corresponding
constructor), so they can not use constructor injection (yet).
DI is used in MVC, WCF, and Task based scenarios in this application.
Whilst I can't talk about WCF and task based scenarios, I can offer my recommendation for MVC (having spent time looking the options to a similar problem myself.
The solution to I've come across and ultimately settled for after seeing recommendations by StructureMap's creator, is to have a HttpContext bound nested container created on each request and stored within HttpContext.Items. From here you can reference the container by casting the instance stored within HttpContext.Items to an IContainer.
Infact, this is the same solution used within the StructureMap.MVC5 nuget package.
With this solution in mind, there's nothing to stop you replacing the ObjectFactory with with your own factory that returns the nested container from HttpContext.Items.
Update:
If HttpContext isn't available to you then the only other options I'm aware of is to create your own instance of the object factory that creates a new container and stores it in a Lazy<T> as suggested here and on the StructureMap's Google Groups page here.
I was going to suggest possiblity posting this question on the StructureMap Google Groups, but I see you've already done that. As an avid StructureMap user I'm keen to see what other suggestions arise from your post so I will be watching closely.
I'm starting off with Java EE 6 after not touching EE for years (I've been in Spring land for a while).
In JSF 2, am I right in thinking that we don't really have controllers any more. That job is done by managed beans?
If so, is it considered normal practice to then inject a 'Service' class (with CDI) into my managed bean to handle the business logic (and subsequently call DAOs)?
I bought a book (PacktPub's 'EE 6 with Netbeans') and read quite a few tutorials but I'm still a little unclear on how to do it right.
As a bonus question, is there a reference 'PetStore' style app that I can download that shows it all linked together in a best-practices kind of way?
Thanks
In JSF 2, am I right in thinking that we don't really have controllers
any more. That job is done by managed beans?
It depends on how you define the term controller. Some people confuse managed beans with controllers but they rather belong to the model part of MVC or are located "between" model, view and controller (see this great answer by Arjan Tijms to a similar question).
If so, is it considered normal practice to then inject a 'Service'
class (with CDI) into my managed bean to handle the business logic
(and subsequently call DAOs)?
This can be done and is normal practice (I do it in all of my projects). But note, that injection does not always work as expected, so for instance you cannot inject a managed bean into a CDI bean (see my answer to a similar question).
As a bonus question, is there a reference 'PetStore' style app that I
can download that shows it all linked together in a best-practices
kind of way?
You could take a look at the Netbeans tutorials. There you find a lot of information about the topic. A visit to BalusC's blog is also highly recommended.
Im really new to Grails and I try to understand how it works. I did some tutorials and wrote a sample application with a mysql database connection. Ive got three tables and therefor three domain-classes and three controller using def scaffold = true. So the views are generated automatically. Now I can add and remove and ... the data in my tables. Thats working.
But now I dont know how to go on. I mean, creating those tables and filling them is nice and its nice that this is possible so fast, but... Now I really want develope an application! Normally I work with Spring Framework, Spring Security, Spring MVC and so on to generate web applications. There, everything is logical. I have the requests comming in, the mapping to controllers, classes which work on the requests, answers given back, jsps rendered.... logical!
In Grails, I dont even know where to start for a real application! All tutorials I find show the same: Setting up those tables and being able to fill them, nice, nice - but after that?
Where do I save the "main.gsp". Do I need a controller for it? How does the application at start up redirect to "main.gsp".
Where can I define the "real logic" - I want to develope something like a "questions with multiple answers - try to select the correct answers"-application. Well, I must admit, I really dont know where to start. And I don't see the use of the Controllers and the possibility to add Data to my tables in my application. Thats for admins but not for users.
Could anyone give me an hint how to go on? Or maybe someone knows a good tutorial which is not about "setting up domain classes, controllers with scaffold, adding data to your database" - I dont see so much sense in it.
Thanks for your help! :-)
[EDIT] Thanks for the answers! Services, that was exactly what I was looking for. I guess I simply must get more familiar with it. The tutorials were just confusing me, but now I understand better!
If you are familiar with Spring and Spring MVC, the concepts in grails should be no surprise to you. Grails actually uses Spring MVC under the covers.
Grails can auto-generate Domain classes, controllers and views as you have tried in tutorials. This is to give you a starting point for your application. This is often enough for those textbook tutorials. For real applications though, you may not always have 1 domain class to 1 controller to 1 set of views. You might not always be doing CRUD operations on that domain. For this, you need to dig a bit deeper into Grails. You can do everything you previously have done in Spring MVC in Grails!
Here are some links to help you get going.
If you are trying to understand the 'flow' better. How requests get mapped to controllers/views, check out the UrlMappings.groovy in your config directory. Docs on that are located here: URLMappings
If you are trying to understand controllers better, check out this: Controllers. Keep in mind that your controller do not need to work on domain models. That is simply the default convention. They work similar to a Spring MVC controller.
Models are simple in Grails. Typically the controllers just return a map of the items you want to return. In Spring MVC, you often create a Model object, most times in Grails you will return something like [name: bean1, name2: bean2]. This allows you to easily get those two beans in the vies.
Start with 'Grails In Action'. The first chapter would give you details about the CRUD Sample app creation , but on reading further you would understand the grails flow better. Services are to be used for the logic, Controllers are used for delegation. You dont need explicit xml mapping as is done in Struts, Spring because everything here works on Convention.
Here is info on controllers: Controllers
Also you can use the same manual to find information on other stuff. For example about where to put business logic you should read in The Service Layer chapter.
Read Beginning Groovy, Grails and Griffon by Vishal Layka, Christopher M. Judd, Joseph Faisal Nusairat and Jim Shingler. They are building a real web application throughout the book with models, database access, authentication, css, templates and layouts, and many other things.
I know to start using areas, you have to establish parent/child relationships. I have a couple areas setup and their controllers are hitting just fine, the problem is some Views are not found. I'm trying to gain an understanding of what's happening to my controllers that are not happening with my Views.
I'm very familiar with MSDN's link but I'm still having a disconnect:
http://msdn.microsoft.com/en-us/library/ee307987(VS.100).aspx
My guess is that maybe it is something to do with the routes. Check to make sure you a registering all of your routes correctly (There's a couple extra things you need to account for when you are using Areas).
Phil Haack wrote a great blog entry on Areas, which may help with your problem.
Edit: Download the ASP.NET MVC source and step through the code to see where it is breaking. This should let you know exactly where the issue is.
Total user error, I ended up creating a new area and forgot to uncomment the child area in the project code behind. Sorry for the mislead! Make sure to uncomment your parent and children area projects!