I Like StructureMap's registry feature for helping me to group IOC Registrations together:
http://structuremap.github.io/registration/registry-dsl/
I'm using DryIOC as my Container - its working great - but I'm in a situation where my registry class needs re-organising. Is there an equivalent Registry feature in DryIOC?
As I understood the Registry feature is similar to Autofac Module, plus some syntax sugar.
Basically it allows to logically group registrations, simplifying the control.
If I am right, here is the example of how to group DryIoc registrations in kinda module, directly comparing with Autofac feature: https://bitbucket.org/dadhi/dryioc/wiki/FaqAutofacMigration#markdown-header-modules
The difference from StructureMap is explicit use of injected IRegistrator, instead of hiding it in the base class.
Related
Creating in-repo-addon in Ember.JS gives a lot of possibilities. Today I've stumbled into a case when I wanted to register all classes in directory (for example my-dir) into Dependency Injector (same way it's done with services by Ember, but I wanted to use some other namespace).
For example I want to allow developer to create multiple classes inside proxy directory, and register all of them in DI under proxy: namespace. So later we can use:
Ember.Component.extend({
myProxy: Ember.inject('proxy:my'),
});
You'll need to do this using an initializer. More details on this here: https://guides.emberjs.com/v2.12.0/applications/dependency-injection/
The hard part may be getting all proxy items in s folder to automatically register ...
Edit
Looks like I didn't spend enough time thinking about this. You should be able to do at least part of this easily. There are two parts to this.
Part 1
Ember currently uses the ember-resolver to handle lookups for various items. If you check the tests for the resolver you'll notice that you should be able to map in anything you want: https://github.com/ember-cli/ember-resolver/blob/master/tests/unit/resolvers/classic/basic-test.js
So in your case, if you do a Ember.getOwner(this).lookup('proxy:main') from within an Ember instantiated class (a route, controller or component for instance) it would look in app/proxy/main.js which your addon could be populating.
Details on the Ember.getOwner lookup are available here: https://emberjs.com/api/classes/Ember.html#method_getOwner
Part 2
So at this point you can lookup proxies (which would be doable in an init method). But if we want to get truly elegant we'd want to allow Ember.inject.proxy('main') syntax.
Doing so would involve calling a private method inside of Ember.inject in an initializer. Because that naming scheme is changing in the new Javascript modules RFC, it may be unwise to try to add this syntactic sugar ...
So I'd advise avoiding touching that private API unless it's really important to your app design.
I'm developing web application using symfony 3. I'm quite new with symfony. I devided my application by bundles. But sometimes I need entities from other bundle. So my question is - should I place entities to some CommonBundle or is it ok to use entities from other bundles?
I would say it is okay to import (use) an entity from another bundle. Keep in mind that this creates a one-way dependency across bundles. If in the other bundle you also import entities (or anything else) from the first bundle, you end up with two-way dependency - in this case the bundles are dependant on each other, and it's impossible to remove one, without modifying another.
I don't think common bundle will help you in this case. I myself also created like a CoreBundle on several projects, but it mostly contained interfaces or some abstractions, and it did not have any dependency on any other bundle.
Some people also suggest creating only one bundle for you app and decoupling the business code from the bundles. But if this is your first time using symfony, I would not recommend you do that.
we can make service to access entity in any bundle in the project
like :-
services:
test_project.list.view:
class: TestProject\TestBundle\Entity\ProfileSchool
arguments:
- "#service_container"
then access the this entity like this in controller :
$view = $this->container->get('test_project.list.view');
Note :
test_project.list.view can be any name,its just demo.
Hope this will help you.
let me know if any issue.
I have an existing Spring MVC + Spring Security + Thymeleaf project. My intention is to add Spring Lemon functionalities to it.
I followed Spring Lemon Getting Started guide, and built a Lemon-powered project. It runs successfully.
Now I'm trying to copy my entities into the Lemon project.
Things go well until I modify my entities to extend VersionedEntity, as said in the documentation.
Then I get this error :
![Error]http://i.stack.imgur.com/snz86.png
Looks like VersionedEntity is incompatible with my ManyToOne relationships. And when I delete those relationships, the problem disappears.
How do i get the tables generated with those JPA annotations ?
VersionedEntity is a lightweight class to support versioning, which extends LemonEntity, which in turn extends Spring Data JPA's AbstractAuditable. So, to pin point where could be the problem, I think you could try extending your classes straight from from LemonEntity or AbstractAuditable, and then see if the issue still remains.
Let's see what you find. If the issue comes even if your entities extend AbstractAuditable, maybe AbstractAuditable isn't compatible with #ManyToOne (assuming your code is fine). In that case, I think raising it with Spring Data JPA guys (either add spring-data-jpa tag to this question or create a separate question with that tag) will help.
Even extending AbstractAuditable didn't solve it. With the help of Sanjay, I understood that when you extend VersionedEntity or LemonEntity, you don't need the Id field in your entity class anymore. Then I deleted it, and it worked.
Previously when I developed ember application I used App as my global object and every class was stored in this big object.
Like this
window.App.MyModel = Em.Object.extend({});
And in the browser console, I was able to do
App.MyModel.create();
So it was really easy for me to access MyModel class.
Now I started experiments with Ember-CLI, I don't have much experience with this kind of tools. I followed the documentations and I created my model Service like this.
var Service = Ember.Object.extend({});
export default Service
But now, how to access Service class from browser console?
Only way I found was:
App.__container__.resolve('model:service')
But I don't like it much. Is there better way? Btw, can you please explain how export works? Or is there some source (documentation, article) where I can study it?
Thanks a lot for response.
If you're aiming to have something available in most places throughout your application you'll typically want to register it on the container.
There are multiple ways to access the container, and you're correct in that the one you found was less than ideal. The running joke is "any time you directly access __container__ we need to add more underscores."
To directly control how things are registered on the container and injected into the container you typically want to use an initializer. Using initializers in ember-cli is super-easy, they're executed for you automatically.
Checking out the documentation you can see that you get access to the application's container as an argument which allows you to manipulate it in a safe manner.
Once you have access to the container you can use register and inject to make content easily available in particular locations. This was introduced here. One note, accessing things inside of the container from outside the context of your app (browser console) will require the usage of App.__container__ and that is the expected use pattern.
And the export you're running into is an ES6 module system construct, it's not Ember-specific. Playing with the ES6 module transpiler can give you a good sense of what goes in and what comes out in "we can do this today" type of JavaScript.
For ember 3.22, application classes can be accessed like so:
Ember.Namespace.NAMESPACES[1]._applicationInstances.values().next().value.lookup('service:state-events')
Note, you may need to modify the index in NAMESPACES[1] to be something other than 1. You can determine which namespace is your application when this returns true:
Ember.Namespace.NAMESPACES[1] instanceof Application
This approach is how ember-inspector accesses ember applications: https://github.com/emberjs/ember-inspector/blob/50db91b7bd26b12098cae774a307208fe0a47d75/ember_debug/main.js#L163-L168
In the notes of this commit, the Ember team have made it very clear that App.__container__.lookup() is not the way to get at controllers. Instead we should use the needs property.
I understand the rationale behind this, and the idiomatic way to access singleton controllers.
However, in my app, I have some cases where I need instance controllers. In that case, I am using App.__container__.lookupFactory() to get at the prototype which I can then create() or extend()
Is there a better way to do this (without using __container__?
Edit:
Here is an example use case.
App.MyContainerView = Ember.ContainerView.extend
...
addChildView: ->
#get("content").pushObject(App.MyChildView.create(...))
The above example will push a new view onto the stack (allowing views to be dynamically created)
However, these views will (may?) not have the right container (and other properties?) set due to being created using App.MyChildView.create(). This is especially true in cases where we are doing a partial integration of Ember into an existing app.
The way to create these views would instead be:
App.__container__.lookupFactory("view:my_child").create()
In which case everything would be ok.
Additional use cases exist, for creating instance controllers outside the context of the router.. but the idea is the same.
I don't know if you're still looking for an answer. I am also struggling with how to do things "the Ember way".
This answer put me on the right track, and should be relevant to your question:
"Please ensure this controller was instantiated with a container"
As for me, I had the same problem as in the above question: when I manually instantiated my App.AnyOtherController with App.AnyOtherController.create(...), then inside this controller, I could not access dependency injections (such as a session object that I make available to all my controllers and routes).
Instantiating the same controller this way solves the problem by giving the controller a container:
this.container.lookupFactory('controller:any_other').create(...)
You should be able to access this.container from any view, and I guess, any controller, as long as they have been given a container.
You can Ember.String.decamelize('AnyOther') to convert the CamelCase controller name to a suitable string.
More on containers here: http://ember.zone/beginning-to-understand-the-ember-js-container/
If it doesn't help you, I still hope this helps someone out there, as this container stuff is a bit tricky at first...