I'm trying to figure out how to define the following StructureMap DSL in my web.config:
For(typeof(ILog<>)).HttpContextScoped().Use(typeof(LogFactoryWrapper<>));
Does the XML approach even support this more unusual type of declaration?
Thanks!
Did you try with:
<DefaultInstance PluginType="path.to.interface.ILog,assembly.withoutdll" PluggedType="path.to.implementation.Log,assembly.withoutdll" Scope="HttpContext" />
Jeremy Dmiller (the father of StructureMap) wrote in his blog:
As for the Xml configuration, it was going to be a near rewrite of the Xml configuration for StructureMap 3.0 and there wasn’t much demand for it. I’m happily open to pull requests if you want it for StructureMap 3.0, but it’s definitely going to be moved to a separate Nuget package because Xml support is not part of PCL.
Related
I’m trying to understand how the Convention plugin determines when to do URL interpretation. In some REST Plug-in examples I see PrefixBasedActionMapper configured with ”/rest:rest,:struts” and it seems that Convention is only applied to the rest mapper and not the DefaultActionMapper. Is this correct? Either way, under what conditions does the Convention plugin kick in for requests?
I’ve been googling like a mad-man these last two days and can’t seem to find any explanation. Inspecting the plugin source didn't give any insights either.
They are different. Convention Plugin is not about URL/action mapping. It just search java classes and create action configs from them.
However, you can tell the plugin to search specific root packages using the property struts.convention.action.packages. e.g.
<constant name="struts.convention.action.packages" value="com.mycompany.myactions.myconvention.*"/>
I'm looking at grails (2.2), and it's all beautiful and even magical, how it all works. I'm looking at a Controller class which is created with grails create-controller and out of the box it has many methods and properties available, like render(), redirect(), params, request and I presume it goes on and on.
where does all this get wired in? Where in the code/project/framework do I see that render() is made available as a method? And how is it implemented?
As a java developer I'm used to inheritance and code injection and reflection. And in javascript prototypes can do some black magic. But the XXController.groovy is just a standalone object. Is it the name (XXController) or the location (grails-app/controllers?) or is there some injection happening which the IDE can pick up?
Welcome to the wonderfull world of Grails,
Here you have a couple of links that may help you:
The Section of Controllers in the Web Layer docs.
And the docs of the render method. Check it out the "Quick reference" column at the right for more methods avaliable at the Controllers.
If you are wondering how that magic is done, Grails is an open source project, so as usual, go and serve yourself at Github (warning, it is quite large project).
Grails works on the top of Groovy, which is a Dynamic Language with a powerful support of meta programming. Tha is basically the trick of all the magic of Grails
Finally, Grails is a framework based on CoC (Convection over configuration), So the Controllers will be any class under the directory "grails-app/controllers" and with the suffix "Controller". (In the folder of controllers may be "commandObjects as well).
The integration with well-know ides is quite powerful as well, you should check it out
EDIT
You may also found how the render methods behaves here at github.
And more inyected stuff at the Controllers metaClass package
As of Grails 2.0+ it's implemented using an AST transformation - previously it was done by adding the methods to the Groovy MetaClass. The benefits of the new approach are that things will be a bit faster and use less memory.
GORM domain class methods now use this approach too (except for dynamic methods like findByFooAndBar which have to be added dynamically to the metaclass) and those have the benefit of being callable from Java since the AST adds the methods to the bytecode. This doesn't help controllers though since they're only called from Grails itself as the result of a web request.
For the gory details, ControllersApi is where the methods are, and they're mixed into each controller class by a combination of ControllerTransformer and the code in the doWithDynamicMethods closure in ControllersGrailsPlugin
Based on advice posted here and here, I looked into and installed MyFaces CODI with my application. My biggest concern was overcoming the shortcomings of Weld's implementation of #ConversationScoped feature. After some hiccups I got it running on my GlassFish 3.1 development platform, and I converted all my beans to use
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationScoped;
In the end it seems like I am now not much further along than I was before. I do not have to call the conversation.begin() method anymore, which is good, but the beans hang around after the browser has left the page and come back.
What I was hoping for was the functionality of JSF 2.0 #ViewScoped that works with CDI. Once the user leaves the page, the backing bean should be discarded and re-created again if the user comes back. Is there a way to do this with CODI?
Incidentally, the documentation says it will pick up the #ViewScoped annotations and process them properly. I tried this and got and Weld wouldn't deploy it.
P.S. I am using myfaces-extcdi-dist-jsf20 version 0.9.5. I tried installing the core and JSF 2 optional module akibe but it would not deploy on my GlassFish/Weld platform. Any advice here much appreciated.
UPDATE 1: I ended up trying the ViewAccessScope annotation supported by CODI, and that seems to do what I wanted.
Follow-up question. The latest bundle that the maven repository that Apache maintains is 0.9.5 -- Can someone post the pom.xml segment that fetches the latest version?
Call conversation.close() before returning - ensure that you imported the correct annotation org.apache... and not javax... - see Wiki or use the ViewAccessScope instead. We are using: bundle in Glassfish 3.1.1 without problems. myfaces-extcdi-bundle-jsf20-1.0.1.jar is the only jar you need. Please also note that there is no "it". With CODI you have fine-grained groupable conversations instead of the monolithic and inflexible stuff you get with standard CDI conversations.
The set-up for the latest version with a Maven build is also in the Wiki.
I want to know why Annotations are preferred over XML in Struts2 Applications?
It's easier to refactor code with annotations than refactor code and then find out you broke your application because you forgot to change the XML file. This is more of a general answer than just for Struts 2, though.
I want to use the MetaDatatType attribute in a MVC6 project and it does't seem to be available yet. I am using 7.0.0-rc1-final so it should the latest.
Does anyone know if it is in another assembly?
I get the error, The type or namespace name MetadataType could not be found.
After some googling it seems like this attribute is not available in MVC 6. You can use it in the full DNX, but it is unavailable in DNX Core.
Of course, you can decorate your code with
#if DNXCORE50
...
#endif
so that you get no errors when compiling for the full DNX, but it looks like the attribute does not do what it is expected. For example, DisplayName(Name = "...") does not work (I didn't check the other options like Required etc.).
IMHO, Fluent MetadataProvider may be a solution to this, only I do not know if it was ported to vNext. I am going to contact the author(s) and if they are not able to port it soon I'll fork it and will make an attempt to port it myself.
EDIT: ModelMetadataType replaces MetadataType. You must reference Microsoft.AspNet.Mvc.Core. I am not quite sure but maybe you'd need Microsoft.AspNet.Mvc.DataAnnotations too.
Anyway, my thoughts about Fluent Data Annotations (Fluent MetadataProvider) are still valid. You may also need to read an interesting article about this: Why You Don't Need ModelMetadata.Attributes by Brad Wilson.
I've ran into same problem. I'm experienced with Asp.NET MVC 5 but I feel a newbie with Asp.Net Core 1.0 (Full Framework 4.6.1). I have a Class Library for models (Framework 4.6.1) using telerik dataaccess core. Using MetadataTypeAttribute for decorating a model class by using a buddy class was almost a headache due to it not worked at all!. Trying almost anything was frustrating. So what was the solution for me?
I had to use ModelMetadataTypeAttribute instead of MetadataTypeAttribute from Microsoft.AspNetCore.Mvc.Core assembly. Decorating a metadata class (buddy class) follows same methodology of using Display(...), DisplayName(...), same for validators. No matter if the buddy class (Metadata Class) is located external from or internal to the model class.
However using MetadataTypeAttribute directly with the model class instead of a buddy class, works perfectly!
The only explanation I could give about this divergence is related with the new emerging Microsoft Asp.Net core technology, relocation of DLL process and functionalities.
PD: It's not required Microsoft.AspNetCore.Mvc.DataAnnotations