Mapping of bundle names onto respective directory path in Symfony2 - symfony

I'm not sure how to put that question. It's a bit fuzzy, but if you encountered the Corpus Delicti, you'll know what I mean.
When I first came across how Symfony2 maps bundles onto paths, few days ago, I already felt bit puzzled about why they chose to map a Bundle name of
AxxBxxBundle onto .../Axx/BxxBundle/...
To me this decision seems arbitrary and confusing, don't get me wrong this is not a serious obstacle and you get used to it within five minutes, but still I think it smells funny.
Now I just came across this quote in the Book:
BundleName:ControllerName:TemplateName
This is the logical name of the template, which is mapped to a
physical location using the following convention.
/path/to/BundleName/Resources/views/ControllerName/TemplateName
And this is wrong I think, there would have to be slash between Bundle and Name.
But this quote shows me that even in the inner Symfony2 circle some people don't find that intuitive.
So what is the "philosophy" bind this bundle thing and its mapping logic?

This doesn't exactly answer the question about the reasoning, but it provides some more information on the Bundle-topic. To get an answer on the why, you should perhaps contact Fabien Potencier who wrote the Symfony\Component\HttpKernel\Kernel class which relies on this convention.

Coming from Zend Framework, it's not that bad for me. All those classes start with Zend_ Thinking of it as the owner/creater's name makes it easier. In java most libraries start with com.foobar
Quoting Fabien: "Symfony2 relies on well-know design patterns, and best practices coming from the Java world."
Your statement does not really make sense or I'm missing your point:
And this is wrong I think, there would have to be slash between Bundle
and Name.
Did you mean: Between Acme and DemoBundle? It does feel like a duplication, but
Quoting Fabien: "A bundle is a structured set of files that implements a single feature and can be easily shared with other developers."
I can use a blog bundle from Acme, then I find a similar bundle from Emca. Most likely their bundles will have the same model&controller&route names. Using them both: this way nothing gets overridden using another library. So the first name for the creator/owner is to prevent duplication.
Since it's a pain to use, I always call mine My/DemoBundle for quicker use :p Or you can give it a custom name during the console bundle generation (if you don't like it)
Also:
All core bundles are treated the exact same as your bundles and
everything is a bundle. Bundles are easily portable and configurable.
They are really the key to Symfony2’s real power. A bundle can extend
another bundle. It can be distributed independently from it’s
application.
Since the web assets are in the bundle, I believe they managed to get it right. That will allow easy configuration and reusability, e.g. bigger (scope) improvements can be made to the symfony core without effecting your app.

Related

What Symfony2 bundle is better for Neo4j integration?

https://github.com/klaussilveira/neo4j-ogm-bundle
https://github.com/jadell/neo4jphp
I am looking for more stable/ more active and wanted to see if you any one had experience with either one of them?
Neo4jPHP is a simple REST client. You don't get any object mapping from it. If you don't like using ORMs and prefer to do your own querying/lookups, it is probably more your style.
Neo4j-OGM is a wrapper around Neo4jPHP that adds in ORM-type capabilities, annotations on your domain classes and a repository pattern. If you have ever used Doctrine or Propel, you will recognize the style and syntax.
My opinion: if you are used to using an ORM or ODM, go with Neo4j-OGM. If you like to do more tweaking and "bare-metal" optimizations, go with Neo4jPHP.

MySql's Connector/Net with MVC 3

I'd like to get some information regarding using MySQL alongside ASP.NET (particularly MVC 3). From what I've found and experienced, it doesn't quite seem as customizable in terms of the Membership and User classes which come with Asp.Net, especially when it comes to validation or registration.
For example, after configuring my web.config file to use MySQL, I found myself realizing that, although a fair amount of tables were auto-generated for me to use, I wasn't able to change the names of them. Because of this, it seemed as though if I were to change a column name, or add a column to the table, it wouldn't quite work with the system, since everything has been pre-built.
Yet, with ADO.Net/Entity Framework, it appears that I might actually be able to have more freedom in how I go about creating my websites using MsSQL. Is this true? Is MySQL just not meant for ASP.Net, despite the the fact that you can install and use it at your leisure. Or is it that it just requires more work to get everything working, and you kind of have to reinvent the wheel by creating your own database classes and validation tools?
I'm not trying to bash either MySql or MsSql, I'm simply looking for a good analysis on the topic, as Google hasn't helped me much in this area.
This is more an issue with the default providers, and one of the many reasons why the 1st thing I did when I learnt about them was to try and make my own. (To be clear, creating your own one from scratch does require a fair amount of work, there are a few good tutorials out there that can give you a quick start)
[It'd make all our lives easier if the .Net framework used Interfaces for the providers rather than the base class... ]
To be clear, the big thing with the auto generated providers is the sprocs they use require the specified names, if you want to change the table names then you'll have to also update all the Sprocs as well. (This is true for any custom provider you may chose to build/use)

Organizing Drupal Code

How do you like to organize your Drupal code? One giant module? Separate modules per feature? Separate modules per code type (theme functions, menu hooks, etc...)?
I've started by trying to organize by feature, treating modules like they were libraries. Ultimately though things are never perfectly contained... modules want to use each other's theme functions, and modules are all contributing various tabs to a common page -- two examples of it not always being so clear where to find code. This tempts me to keep all theme functions together, and all hook_menus together, but this would be awkward for other reasons...
Assume that all code is too specific to eventually share, so there's no attempt here to make self contained contributed modules. I'm mostly concerned about maintaining sanity and cleanliness in a large scale Drupal site.
I tend to have a folder with one main module with all the shared functions, and a variety of sub-modules that are broken up by logical functional divisions. I've found the single huge module approach makes finding stuff in it rather unfun.
It really doesn't make much of a difference if you're not distributing it on Drupal.org, though, so whatever makes sense to you is fine.
I load all customizations into a single module per project (menu/form/link alters, etc.). If enough customization is done, I will fork the original module or create a new module with the original module as a dependency. It's at this point that it pretty subjective: I have no hard and fast rule saying 'fork a module when I reach this many function points or lines of code'.
Anything that adds functionality (meaning that it doesn't override something else) goes into it's own module.
If any newly created or forked modules can be used in other projects or contexts, I will publish them to my personal repository.
I most often use a single module and a set of include files where I store my classes. Although views uses more than one module, it is a great example of the this strategy. Take a look at the views module includes folder to see what I mean.

ASP.NET plugin architecture: reference to other modules

We're currently migrating our ASP Intranet to .NET and we started to develop this Intranet in one ASP.NET website. This, however, raised some problems regarding Visual Studio (performance, compile-time, ...).
Because our Intranet basically exists of modules, we want to seperate our project in subprojects in Visual Studio (each module is a subproject).
This raises also some problems because the modules have references to each other.
Module X uses Module Y and vice versa... (circular dependencies).
What's the best way to develop such an Intranet?
I'll will give an example because it's difficult to explain.
We have a module to maintain our employees. Each employee has different documents (a contract, documents created by the employee, ...).
All documents inside our Intranet our maintained by a document module.
The employee-module needs to reference the document-module.
What if in the future I need to reference the employee-module in the document-module?
What's the best way to solve this?
It sounds to me like you have two problems.
First you need to break the business orientated functionality of the system down into cohesive parts; in terms of Object Orientated design there's a few principles which you should be using to guide your thinking:
Common Reuse Principle
Common Closure Principle
The idea is that things which are closely related, to the extent that 'if one needs to be changed, they all are likely to need to be changed'.
Single Responsibility Principle
Don't try to have a component do to much.
I think you also need to look at you dependency structure more closely - as soon as you start getting circular references it's probably a sign that you haven't broken the various "things" apart correctly. Maybe you need to understand the problem domain more? It's a common problem - well, not so much a problem as simply a part of designing complex systems.
Once you get this sorted out it will make the second part much easier: system architecture and design.
Luckily there's already a lot of existing material on plugins, try searching by tag, e.g:
https://stackoverflow.com/questions/tagged/plugins+.net
https://stackoverflow.com/questions/tagged/plugins+architecture
Edit:
Assets is defined in a different module than employees. But the Assets-class defines a property 'AssignedTo' which is of the type 'Employee'. I've been breaking my head how to disconnect these two
There two parts to this, and you might want to look at using both:
Using a Common Layer containing simple data structures that all parts of the system can share.
Using Interfaces.
Common Layer / POCO's
POCO stands for "Plain Old CLR Objects", the idea is that POCO's are a simple data structures that you can use for exchanging information between layers - or in your case between modules that need to remain loosely Coupled. POCO's don't contain any business logic. Treat them like you'd treat the String or DateTime types.
So rather than referencing each other, the Asset and Employee classes reference the POCO's.
The idea is to define these in a common assembly that the rest of your application / modules can reference. The assembly which defines these needs to be devoid of unwanted dependencies - which should be easy enough.
Interfaces
This is pretty much the same, but instead of referring to a concrete object (like a POCO) you refer to an interface. These interfaces would be defined in a similar fashion to the POCO's described above (common assembly, no dependencies).
You'd then use a Factory to go and load up the concrete object at runtime. This is basically Dependency Inversion.
So rather than referencing each other, the Asset and Employee classes reference the interfaces, and concrete implementations are instantiated at runtime.
This article might be of assistance for both of the options above: An Introduction to Dependency Inversion
Edit:
I've got the following method GetAsset( int assetID ); In this method, the property asset.AssignedTo (type IAssignable) is filled in. How can I assign this properly?
This depends on where the logic sits, and how you want to architect things.
If you have a Business Logic (BL) Layer - which is mainly a comprehensive Domain Model (DM) (of which both Asset and Employee were members), then it's likely Assets and Members would know about each other, and when you did a call to populate the Asset you'd probably get the appropriate Employee data as well. In this case the BL / DM is asking for the data - not isolated Asset and Member classes.
In this case your "modules" would be another layer that was built on top of the BL / DM described above.
I variation on this is that inside GetAsset() you only get asset data, and atsome point after that you get the employee data separately. No matter how loosely you couple things there is going to have to be some point at which you define the connection between Asset and Employee, even if it's just in data.
This suggests some sort of Register Pattern, a place where "connections" are defined, and anytime you deal with a type which is 'IAssignable' you know you need to check the register for any possible assignments.
I would look into creating interfaces for your plug-ins that way you will be able to add new modules, and as long as they follow the interface specifications your projects will be able to call them without explicitly knowing anything about them.
We use this to create plug-ins for our application. Each plugin in encapsulated in user control that implements a specific interface, then we add new modules whenever we want, and because they are user controls we can store the path to the control in the database, and use load control to load them, and we use the interface to manipulate them, the page that loads them doesn't need to know anything about what they do.

Proper way to build a data Repository in ASP.NET MVC

I'm working on using the Repository methodology in my App and I have a very fundamental question.
When I build my Model, I have a Data.dbml file and then I'm putting my Repositories in the same folder with it.... IE:
Data.dbml
IUserRepository.cs
UserRepository.cs
My question is simple. Is it better to build the folder structure like that above, or is it ok to simply put my Interface in with the UserRepository.cs?
Data.dbml
UserRepository.cs which contains both the interface and the class
Just looking for "best practices" here. Thanks in advance.
General best practice is to have one class or one interface per file.
Here's the more generic discussion, which I think applies to your case:
One class per file rule in .NET?
As a developer new to your project, I would appreciate knowing that IUserRepository exists--without having to fish through your UserRepository.cs file.
Do whatever makes sense to you.
Personally I find browsing solutions for anything painful so I have hot keyed Goto Definition/Implementation and Resharpers FindUsages Go to Type, Go to File so I never have to click anything.
Combining interfaces and classes in one file makes sense if the class or interfaces are small.
Also if your following the Liskov substitution principal / a dependency injection strategy and general good design practices you would rarely be interacting with actual implementations anyway. Repositories should almost never be referred to by their concrete implementation.

Resources