We are converting windows applications to browser based in .Net using Visual Studio 2010. While I'm not new to .Net, I am new to creating applications based on 3 tier architecture. I want to create classes for each table in our database and put them under a Namespace. The class name will be the same as the table name, so each class in the the Namespace would be referenced something like CompanyName.ProductName.Entity.{table name}. Now for my questions:
Is this feasable?
Would I create seperate project for each table class? Note that new table classes will be created as more programs are converted.
Does this create one huge .dll?
How do other developers access the classes I created, and where are they stored so I can reference the classes with the Using directive?
Always create the class names with individual cs file, so it will be easy to do versioning of files. It does not relate to size of dll if we keep the class in a single file or multiple files.
Create the folder structure like Project > ProductName > Classes in your solution.
Would I create seperate project for each table class?
No, don't create a separate project for each table class. That's too granular.
Does this create one huge .dll?
Each project would create a separate DLL by default (I believe you can do things with IL merge to change that.) However, each namespace does not have a direct relationship to DLLs. That is, you can have multiple namespaces in a single DLL.
What we've typically done is create a DAL library. This would be it's own project, usually named something like ProductName.Data Then within that we might have a namespace like ProductName.Data.Models or ProductName.Data.Repositories.
Namespaces are largely used to help YOU organize the code. They also help out the compiler. For example, if you have a database class named Users, and it's in XYZ.Data, you can still have a view model named Users if it's in a separate namespace, e.g. XYZ.ViewModels.
Another thing that we've done is to keep the root namespace the same across DLLs for the same product. So we recently had our database in XYZ.Data. Then we put our application specific logic in a separate DLL and named it XYZ.AppLogic We also had view models in the namespace XYZ.ViewModels.
I don't believe there are any hard/fast rules that limit the number of namespaces you have. By default, Studio will try to create a new namespace for each folder in your project. That said, I often try to avoid namespace overload, because I don't want to see something like this at the top of my files:
using XYZ.Data.Models.Accounts;
using XYZ.Data.Models.Users;
using XYZ.AppLogic.Authentication;
using XYZ.AppLogic.Users;
using XYZ.AppLogic.Settings;
using XYZ.ViewModels.UserPreferences;
However, that's more of a personal preference than anything else.
EDIT Solution View
MySolution
MyProj.Data
Models
User.cs
Account.cs
Settings.cs
Repository
UserRepository.cs
AccountRepository.cs
User.cs is my POCO (Plain Ol' CLR Object) that defines the table.
The Repository folder has things specific to my ORM (I'm using PetaPoco) which let me actually access my user data.
For example, my UserRepository might have a method
public User GetById(int id)
{
var db = new Database(<myConnectionStringName>);
return db.SingleOrDefault<User>(id);
}
That syntax is specific to PetaPoco, but it is how I separate the data object from the actual DB connection.
The simple answer that I was looking for is to create one solution with my namespace as the default namespace. For each file, create a new class, and specify the namespace in each. Thanks to all who responded.
Related
I am little confused before starting a new project in Yii2 advanced template. So, i am asking this question.
I have done some projects in "Yii2 basic" app in which we use modules for different parts of our application like for adminpanel, api we create different folders in 'modules folder'.
I had also done a project in Yii2 advanced template it was multiapp project so we used advanced template. As we already had 'backend' and 'frontend' separated in Yii2 advanced template so we didn't created any module in 'modules' folder.
Now, i want to ask what is right approach. like in my new project we have users and products in backend so is it appropriate to create different modules for them in 'modules' folder or will it be ok if i create there controllers and models directly in backend folder.
what are the advantages of using modules folder in advanced template?
Thanks for answers in advance.
The advantage of module's use is primarly the possibilities of a resue of this components in several diffferente project. you can easly separate you common repetative functionalities in several modules and use the same code in different prject indipendently of the "template" or scaffolding you use for the single applicazione or group of applications.
Do the fact the modules are self-contained software units that consist of models, views, controllers, and other supporting components
modules are, not only usable as a sort of mini-applications, but also as a easy way for code organization and reuse.
Modules are used to reduce our work.
Example:
In most of projects have user login function like login , signup ,
forget passsword ,password reset.
If you write code for these functions as module . You can use any
project
So there is know need to write one code again and again.
I want to create a Processing library that adds a single function to Processing. A single command. How do I do this?
So I want to be able to write on Processing this:
void setup() {
drawMyCustomShape()
}
In a way that drawMyCustomShape will be on my custom library implementation.
Thanks!
Note: this question is not about creating a new library in processing. Is about creating a library that exports one new command (so you can using without caring of the container class instance).
First of all, are you sure you really need to create an entire library? You could just add that class to your sketch without needing to deploy it as a library. If you're worried about clutter, just put it in its own tab.
If you really need to create a library, then there are three tutorials that you need to read:
Library Overview
Library Basics
Library Guidelines
But basically, you need to create a Java project (in an IDE like eclipse, or with a basic text editor and the command line) that uses Processing as a library. That's where you'd put your MyLibrary class. You'd then export it as a .jar file, and then import that .jar file into Processing. You would then be able to use your class exactly like you can use any other Processing library.
Your proposed setup has some other issues (how are you going to access the sketch variable from the static function?), but I'd suggest treating them as separate questions after you get the basics in place.
It sounds like you are actually looking to create your own extension of the Processing library, as in actually change the core jar file.
You can extend the actual Processing library by forking off of its main branch on Github. By writing your function drawMyCustomShape into the actual core in the forked version, you can then build the Processing Development Environment from your copy of the code. Using that particular copy of the PDE, you could do what you're describing.
Once you compile this build, you could actually distribute this copy of the PDE to your college students. They would be able to use your function as if nothing were changed. (I'm guessing that this is for an intro-level class at the college level, so that's why you would have to hide implementation from your students?)
Here's some links to get you started:
Processing github
Instructions for building the PDE from source
So, finally I found the most adequate answer for my case.
The solution for this is to implement a new Processing Mode that extends the builtin Java Mode. To include static members to the main processing program you will need to add a new static import to the ones that processing adds to your code.
You can do this by forking the Mode Template for 3.0 that #joelmoniz created from #martinleopold:
https://github.com/joelmoniz/TemplateMode/tree/3.0-compatibility
There is a good tutorial here:
http://pvcresin.hatenablog.com/entry/2016/03/17/210135
Why is the most adequate solution? : I think this is the best way to achieve new static methods in processing code and ensure an easy distribution! You just have to set the mode folder in your sketchbook/modes folder. If I were to fork processing it would be a big deal to prepare distributions for all operative systems and also to keep update with main project.
My particular solution:
To add my static imports into Processing I implemented a custom mode where I overrode the PdePreprocessor class which wraps the processing code with all the Java procesing code. So, the idea was to add more imports to the imports that the PdePreprocessor generates on the generated Java source.
In my custom PdePreprocessor I overrode the getCoreImports method to add my custom methods. I did this here because I consider the new imports are part of the core of my custom mode. You could also achieve this by overriding writeImports method.
In order to use my PdePreprocessor implementation I had to overrode the following classes:
Commander
JavaBuild
JavaEditor
JavaMode
JavaEditor
I had to implement a new JavaBuild which preprocesses the Sketch with my custom PdePreprocessor. And also use my custom JavaBuild in all the places where the Processing Java Mode instances the build class. Please share with us if there is a better way to do what I did.
Here is the github for my solution: http://github.com/arypbatista/processing-inpr/
I am using web API to provide some web services.
There is a linq to sql datacontext which is auto-generated from database and I use it in my API methods.
Now for documenting, I need to add XML comments to the classes and the properties and methods of them, from the auto-genereated datacontext.designer.cs
When I open up the .designer.cs file and force add my XML comments to it, it works and showed up in the documentation section of the website. But as you know, it is auto generated file, and when I change the model, all my comments will disappear.
what can I do to solve that?
Thanks in advance.
Create a partial class (in a different file) for the class defined in the designer.cs file and move the property you want to change the XML comments from the designer.cs file to your newly created class. Then add the appropriate comments and they will stay there, no matter how many times the auto generated one is recreated.
Now I have AppA finished. but I want to make AppB,AppC. and AppB,AppC share most of the code in AppA(including xaml, asset, code,etc.). only a few changes for the AppB,AppC respectively.I mean, the 3 apps can be installed on the same windows phone separately with different icons.
Does anybody know how to build AppB,AppC referring AppA in code?
thanks.
Either extract as much as you can in a shared/common project or use "Add as Link" to include files from AppA into AppB and AppC.
Note that XAML files don't support conditional compilation so they must be identical for all projects in order to link them. You can potentially extract XAML differences into App.xaml StaticResources (identical keys) in order to make them identical and link them.
Sharing XAML is very reasonable when targeting the same platform.
You can also link cs files even if they are similar (few changes) by using conditional compilation.
Partial classes can also spare you the conditional compilation ceremony in many cases.
Finally Resource files are very good candidate for reuse. If you decide to put them on a shared library remember to wrap the generated Resource class in another public one with a public constructor shown here in order to avoid the internal constructor issue.
You can put all your code in an external class library. As far as I know though your assets and pages need to exist in each project.
If you want to share code and assets between multiple assemblies, you can create a class library for Windows Phone and put all the code inside it. When you need to use that library, simply link it in your target applications.
When you want to navigate to a page in your library, use the following syntax:
NavigationService.Navigate(new Uri("/AssemblyName;component/page.xaml", UriKind.Relative));
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.