How can I divide unity configuration section into several files? - configuration

In my project there is some common package which gets its dependencies resolved by the UnityContainer which is defined in unity.config file.
There is another custom package which I want to have its own custom UnityContainer in a seperated CustomUnity.config file.
In runtime I want both files to be loaded and when I get the unity section, I want it to contain both UnityContainers.
How can i achieve it?
Thanks!

The UnityContainer.LoadConfiguration method can be called multiple times on the same container. Each time it loads whatever's in that configuration section, but it doesn't remove what was previously in the container - it's additive. If there's a conflict (both sections configure the same type) then last one in wins.
So, the approach would be to use the ConfigurationManager APIs to load your two separate UnityConfigurationSections, and then call LoadConfiguration twice, once for each configuration section. That should be all you have to do.

I wrote a library that lets you write your ioc container configuration in modules. It supports unity but you will have to configure your container in codes instead of using the files. I don't know if will solve your problem, but you can check it out at bootstrapper.codeplex.com

Related

How to include page from one package into another?

I am trying to create a package which will collect UIs from various WM packages into one.
I have the core site in pub folder of one package and wanted to use %include% method.
But, if I wanted to use entire URL, it doesn't work. neither using just pathname.
Only what will allow to load the page from another package is relative path to the index.dsp of the package.
%include ../../../anotherPackage/pub/index.dsp%
Problem with this solution is that in case that the anotherPackage/pub/index.dsp contains also some includes locally from the package then they are not loaded because the "cursor" is still pointing to the master package from which I have the anotherPackage/pub/index.dsp included.
Anyone fought with same problem?
Exists there any other way than how to solve it?
Thanks, Reddy

How to pass directives to snappy_ec2 created clusters

We have a need to set some directives in the snappy config files for the various components (servers, locators, etc).
The snappy_ec2 scripts do a good job at creating all of the config's and keeping them in sync across the cluster, but I need to find a serviceable method to add directives to the auto generated scripts.
What is the preferred method using this script?
Example: Add the following to the 'servers' file:
-gemfirexd.disable-getall-local-index=true
Or perhaps I should add these strings to an environments file such as
snappy-env.sh
TIA
-doug
Have you tried adding the directives directly in the servers (or locators or leads) file and placing this file under (SNAPPY_DIR)/ec2/deploy/home/ec2-user/snappydata/? The script would read the conf files under this dir at the time of launching the cluster.
You'll need to specify it for each server you want to launch, with the name of server as shown below. See 'Specifying properties' section in README, if you have not already done so. e.g.
{{SERVER_0}} -heap-size=4096m -locators={{LOCATOR_0}}:9999,{{LOCATOR_1}}:9888 -J-Dgemfirexd.disable-getall-local-index=true
{{SERVER_1}} -heap-size=4096m -locators={{LOCATOR_0}}:9999,{{LOCATOR_1}}:9888 -J-Dgemfirexd.disable-getall-local-index=true
If you want it to be applied for all the servers, simply put it in snappy-env.sh as you mentioned (as SERVER_STARTUP_OPTIONS) and place the file under directory mentioned above.
We could have read the conf files directly from (SNAPPY_DIR)/conf/ instead of making users copy it to above location, but we may release the ec2 scripts as a separate package, in future, so that the users do not have to download the entire distribution.

Sharing source between 2 projects?

I have a project containing a big package "global" of classes which is designed for Web, I need to share these classes with a new mobile project, but when i add them with :
Properties -> Flex Build Path -> Source path -> Add Folder
they start appearing with index [source path] before the package name, and since them Flash Builder start trowing error messages :
"A file found in a source-path must have the same package structure '', as the definition's package, 'global'."
How can i fix this issue ?
As we've discussed in the comments, I think it would be a better approach to compile your "global" classes into a library (.swc).
You were concerned about loading unnecessary classes: when you link to a library as 'merged', only the classes you use are actually compiled into the main application (and any classes they depend on), so there's no need to worry about that.
As a last argument I also think this is a more flexible approach. A compiled library is easier to reuse and version, so the code can more easily be distributed to other developers on your team.
Rename one of the packages with right click->refactor. Than is should work.
If not you can also try to have your two codes available at the same project, and then you can select which to run in Flash Builder, by right-clicking to that .as or .mxml file, and selecting set as ... (or something like that)
I guess if you will include 'src' fonder instead of 'src/global' that problem will disappear.

Entity Editor - How to dynamically generate a list of components?

I'm making a game and I an in-game editor that is able to create entities on the fly (rather than hard coding them). I'm using a component-aggregation model, so my entities are nothing but a list of components.
What would be the best way to obtain or generate a list of components? I really don't want to have to manually add entries for all possible components in some giant registerAllComponents() method or something.
I was thinking maybe somehow with reflection via either the knowledge that all components inherit from the base Component class, or possibly via custom metatags but I haven't been able to find ways to get a list of all classes that derive from a class or all classes that have custom metatags.
What sort of options am I left with?
Thanks.
For a project I did once, we used a ruby script to generate an AS file containing references to all classes in a certain package (ensuring that they were included in the compilation). It's really easy considering that flash only allows classes with the same name as the file it's in, so no parsing of actual code needed.
It would be trivial to also make that add an entry to a dictionary (or something similar), for a factory class to use later.
I believe it's possible to have a program execute before compilation (at least in flashdevelop), so it would not add any manual work.
Edit: I added a basic FlashDevelop project to demonstrate. It requires that you have ruby installed.
http://dl.dropbox.com/u/340238/share/AutoGen.zip
Unfortunately, there is no proper way of getting all loaded classes or anything like that in the Flash API right now. So finding all sub-classes of Component is out, inspecting all classes for a specific meta tag is out as well.
A while ago I did run into a class/function that inspected the SWF's own bytecode upon loading to retrieve all contained classes. That's the only option for this kind of thing. See this link and the bottom of my post.
So, you're left with having to specify a list of component classes to pick from.
One overly complicated/unfeasible option that comes to mind is creating an external tool that searches your source folders, parses AS3 code and determines all sub-classes of Component, finally producing a list in some XML file. But that's not a task for the faint-hearted...
You can probably think of a bunch of manual solutions yourself, but one approach is to keep an accessible Array or Vector.<Class> somewhere, for example:
public static const COMPONENT_LIST:Vector.<Class> = Vector.<Class>( [
CollisionComponent,
VisualComponent,
StatsComponent,
...
...
] );
One advantage over keeping a list of String names, for example, would be that the component classes are guaranteed to be compiled into your SWF.
If the classes aren't explicitly referenced anywhere else in your code, they are not compiled. This might occur for a simple component which you only update() once per frame or so, and is only specified by a string in some XML file.
To clarify: You could use the code in the link above to get a list of the names of all loaded classes, then use getDefinitionByName(className) for each of them, followed by a call to describeType(classObj) to obtain an XML description of each type. Then, parsing that for the type's super-types, you could determine if it extends Component. I personally would just hardcode a list instead; it feels too messy to me to inspect all loaded classes on startup, but it's up to you.

Maintain 1 codebase for SWF that is sometimes standalone, sometimes module

I have an app that has been a standalone app 'til now; however, in another app it's going to be a wee little module.
Is it possible to somehow maintain 1 codebase when the standalone has a source tag of:
<mx:Application>
and the module has a source tag of:
<myModuleBase>
Or is it better to keep a separate branch and just merge them together when the standalone has new changes that I want to propagate to the other?
The standalone app will eventually be taken down as part of phase 2 of this new project but that is several months off and features may be added in the interim.
Can I do this with a separate application file?
Thanks for any helpful tips!
This shouldn't be too difficult to implement. (Disclaimer: I have not messed with modules in Flex)
You have two top-level files, appNameStandalone.mxml and appNameModular.mxml
Those only include the main mx:Application and MyModuleBase tags, and contain inside them an MXML component that represents the actual application.
//appNameStandalone.mxml
<mx:Application ...properties>
<myComponents:UIAndFunctionalityComponent/>
</mx:Application>
//appNameModular.mxml
<MyModuleBase ...properties>
<myComponents:UIAndFunctionalityComponent/>
</mx:MyModuleBase>
If you're not certain how to do this in practice (say, in Flash Builder), you can work under one project directory with two Flex Applications (Project -> Properties -> Flex Applications) or have two separate projects containing only the top-level MXML file with the source folders containing the remainder of the application in the build path (Project -> Properties -> Flex Build Path -> Source Path).
If I've got some misunderstanding as to how the modular version works, please let me know and I'll attempt to correct my answer.