flex/air how to load a class that is on another module - apache-flex

I´m trying to build my flex modular app, and got the following scenario
Portal (which includes, 2 modules:)
-Mod1 (.swf)
-Mod2 (.swf)
Also, i have Mod1-API (.swc)
The Mod1-API, defines interfaces which are implemented on the Mod1 (.swf).
Both the Mod1 and Mod2 swfs import the Mod1-API swc.
I´m trying to call the API method on the Mod2. On Mod2 I´ve the interface, since it is shared via the Mod1-API project.
What I´m trying to achieve is the real implementation class loading on Mod2, via reflection, using the getDefinitionByName method, but it says its not defined.
So, is there a way to achieve it?
I mean, how from the mod2 load a class that is on the Mod1 project, returning just the interfacce to the mod2 so it can call methods just like an ordinary API method?

It depends on where you are loading your class definitions. Flex uses both Security Domains and Application Domains to partition code which has been loaded.
If you want Module 2 to access code loaded via Module 1, they need to be loaded into both the same security and application domains.
This should give you a good start.

Related

Using Interfaces among multiple Projects ASP.Net

I have one project with multiple libraries. The problem I have is that I can’t access some libraries from others, as when I add a reference I get an error about circular dependencies. I assume I need to create an interface but I am not really sure how to structure it. Here is an example of what I have:
My references are setup like this:
WebApp (This is an ASP.Net web site) - Has Reference to BusinessLayer Class Library and Utilities Class Library
Data Class Library (This library provides abstract database functionality) - has no references
BusinessLayer Class Library (provides a business logic layer) - has references to Data Class Library, DataLayer Class Library, and Utilities Class Library
DataLayer Class Library (provides a layer that directly interfaces with the database i.e. CRUD commands) - has references Data Class Library and Utilities Class Library
Utilities Class Library (general library that are used across all layers) - has no references
For the most part this is fine. But, I have a class in the Utilities Class Library that needs to reference functions and properties in the WebApp and BusinessLayer Class Libraries. I cannot add a reference to these projects, as that would create a circular dependency. So, how would I go about setting up the Interface and the correct references?
The way you have designed your application is very similar to architecture pattern defined
here
As for your utility class, you can define an interface in BusinessLayer/domain layer and implement that interface in utility layer. Please note it should only return types defined in business layer/domain. This way you will get a nice separation of concerns. If let's say your web needs to consume this utility method, you can apply transformation to convert your domain type into web project specific type. This way you won't run into circular dependency.
I created a sample application based on these principles, you can refer to my github
project.
It sounds like you need to move those common functions out of webapp and into your utilities library. I don't think you should be referencing your web app from any of your other libraries.

Reference problems when using custom controls within Exrin

Using the base Exrin template, I am unable to use custom controls.
As it stands now, the Droid/iOS projects reference the App/Bootstrapper project, so that seems like the correct place to put them, but when creating a new page or BaseView, I am not able to access the custom control's namespace because the View project does not reference the App/Bootstrapper project.
The Tesla sample app does not have this problem in its current implementation since there is no separation of the App/Bootstrapper and the View projects.
(1) Should a reference to the App/Bootstrapper be placed in the View project or (2) should a reference to the View project be placed in the Android/iOS/etc projects? Or is there a better solution than either of these two?
Edit:
(1) does not work because a reference to the App project from the View would create a circular dependency.
(2) should work (I think), but I'm having trouble getting the Application.Droid project to access the Application.View project namespace because when I add using Application.View;, the namespace isn't found in the Application namespace. Visual Studio attempts to fill in other Application namespaces (.Container, .Logic, .Droid, .Proxy) when I type in using Application.
The native project can have a reference to the View. It already does in a way, because it references the App library, which then references the View. Hence you aren't really adding any further dependencies by doing this, just allowing access further up the chain.
If you are having trouble the namespace, I suggest you start out with
global::Application.
That way it starts from the top, if its getting mixed up with project namespaces.

jax-rs url inside an ejb module

I created a tutorial that incorporates various components of J2EE in them. The app is an ear module that has an ejb project and a web project.
the project structure is
john-app
john-ear
john-ejb
john-web
the ejb project has a couple dao that perform basic crud operations using jpa. I'm trying to learn/understand jax-rs to gain a better understanding of json and handling json objects. the project is loosly based on
this project:
http://www.developer.com/java/creating-restful-web-services-with-jax-rs.html
so, i created my BookResource here and made it a stateless ejb. i have everything compiling and deploying without any obvious errors - other parts of the app work (the jpa stuff) but i can't get the jax-rs stuff to
work. i have a couple of"Books" that I created in my database and am wanting to test this by making a rest call through the browser.
so i deploy my .ear file in wildfly (v10) with no obvious errors, I see JNDI mappings for my EJB's...etc
initially, i'd like to be able to test this through my browser, but am not certain what url to use -- the class i have extending javax.ws.rs.core.Application has an application path of /rest and my
BookResource has a path of /library, and for getting all books from the library, the sub-resource is books. I've tried every combination of the url below,
http://localhost:8080/john-[app|ear|ejb|web]/rest/library/books
all to no avail. every call results in a 404 error, and the only time i got ANYTHING is when i tried john-web combination, it threw some ugly exception in the browser. so the questions is with a rest service living inside an ejb module within an ear, what should the url be given the above information. nothing i've tried
seems to work!??
I've not included any code samples to try and keep the explanation short -- i didn't want to include every java file in my little project, but can add anything as requested.
Thanks,
JG

Dynamically extract interfaces from silverlight modules and load modules

In some winforms / webforms applications, I wrote a module that at application start, using reflection, inspects all assemblies from BIN folder, extract all public classes and interfaces they implement and write into a repository. This to to allow me later, at runtime, to load modules based on interfaces they implements and use.
I need to know if / how can I accomplish this for Silverlight. Is there any way to inspect all XAP's and extract all modules together with their metadata? And later to be able to dynamically load the module where the component I need is located, and then load the component from it.
Thank you
The source code for MEF's DeploymentCatalog should show how to inspect the main application XAP as well as download and inspect other XAPs.

ASP.NET with Unity 2.0

Can anyone help point me to some good resources for working with Unity 2.0 in an ASP.NET that doesn't talk about ASP.NET MVC?!?
We are not using MVC and I am struggling to get Unity to inject dependencies into my pages following the couple of examples I've read (which are all based on David Hayden's work so they are all presenting the same examples and code).
UPDATE
I tried to go the PageHandlerFactory route but the example (here) is incomplete and no source code is available to accompany the article.
So, I decided to try the custom HttpModule approach described here and here. Again, no source code is available beyond what is shown so it is difficult to troubleshoot issues.
The problem I have now is that all of the plumbing appears to be wiring up correctly but the Buildup method does nothing to my page. I can see all of the types are registered in the container when I set a break-point in the module code and the code is executing as expected. But a break-point in the Page_Load event handler shows that the dependencies are all null.
The property in question is public, with a setter and getter, and is marked with the Dependency attribute. I've tried with and without the attribute, with and without a mapping name, ... every combination I could think of and nothing works.
What am I missing???
It depends what you expect. Most exemples targeting MVC present custom controller factory which allows creating controllers with dependency injection. This is indeed also possible with web forms but instead of controller you must inject dependencies into pages. To do this you must replace PageHandlerFactory with custom implementation.
You can create your own implementation of PageHandlerFactory which will be able to resolve pages directly and inject dependencies defined in constructor or you can use one of these (here, here and here) which instead uses stantandard PageHandlerFactory and builds page instance (resolve property dependencies).

Resources