Accessing Classes in Asp.net - asp.net

In web application, i am created one new project in that i added class library, like business layer, datalayer, but when i am accessing the business class in datalayer, class object is created but, when i am accessing the fileds of that class like example :
EmpBL objEmb= new EmpBL();
objEmb is not coming in intellesence, even i am not accessing the fileds of business class can you help me out please.

right click on your data layer project, select Add Reference and select Project tab - then add reference to your .Business project.
However, you can now have circular references, i.e. you can't reference each other. And normally, Business Objects project references Data Access project, not the other way around. Although any architecture is possible, and sometimes BOL project is just storage classes, and they don't know anything about DAL - a third project brings them together. Not sure about your exact architecture.

Related

Identity 2.0: ApplicationUser extension using a database first approach

From a couple of articles I have found online
http://typecastexception.com/post/2013/10/27/Configuring-Db-Connection-and-Code-First-Migration-for-Identity-Accounts-in-ASPNET-MVC-5-and-Visual-Studio-2013.aspx
http://www.codeproject.com/Articles/790720/ASP-NET-Identity-Customizing-Users-and-Roles
I have seen it is very simple to extend the ApplicationUser class in MVC 5/Identity 2.0. It basically requires adding of property to that class and all dependent views/viewmodels etc to implement the new functionality. The only question I have remaining is due to the fact that these articles all give you examples in regards to a code first perspective. How would extending the Applicationser class work with a database first perspective?
Here is what I imagine.
1.) Change the connection string to your production database. (In my case SQL Azure)
2.) Create the tables that are normally automatically created by identity 2.0 in SQL Azure.
3.) Fill those tables with the default properties and types.
4.) Add custom properties to the AspNetUsers table. (E.G. City, Zip, etc)
5.) Add those properties to the actual ApplicationUser class
6.) Update dependent views, controllers, viewmodels etc.
Is there a more simple way in doing this?
No, there is no other way to extend ApplicationUser. Code-First is pretty much the same, only adding properties first, create migration, run migration, update your controllers/views.

Repository pattern in Web Forms

i have used the repo pattern in my web forms application in the following way
UI Layer:
it contains the code behind files in which the controls are being binded and user actions like insert update etc are catered for
the UI Layer calls the
Repository Layer:
it contains the repository classes inheriting the GenericRepo:IGeneric
and the
Data Layer:
it contains the EF generated domain classes
the layers are strict for the time being that is the UI layer calls the Repo layer and it in turns call the data layer to fetch the data.
Problem:
now the problem im facing is that if for example i need a list of products on the Products.aspx page i need to do some thing like
IProductRepo pr = new ProductRepo();
IList<Products> lstProducts = pr.GetAll();
i dont want to add the reference of Data Layer to the UI layer in order to access the domain entities i.e generated by the EF
what are my options? please guide me to the right path
regards.
In my opinion you're missing a layer. I would built it like this:
UI |
----- |
**Domain** | Domain classes
----- |
DAL (Repository) |
This way your logic is in a separate layer and your DAL is completely hidden from your logic and domain model.
Another way you could solve this problem is by using Dependency Injection. That way you can define some interfaces and only keep references to interfaces. With a dependency container you can ten tie those references to real types.
My preferred DI container is for example Ninject

MVC3 with EF Dbfirst, how to generate "controller with read write actions and views"

I am learning MVC3 and EF with DB first approach.
In some videos of MVC3 with code first approach from Scafolding Options they choosed "controller with read write actions and views" and after selecting Model and Data Context classes some code was automatically generated.
In my working I have a separate class library which has EF model in it (please see blue selected area in diagrame) . Please guide me how to access that EF and its generated classes to use with controller with read write actions and views ?
EDIT
I am adding new Controller.
I am not getting the comments you mentioned in your picture.
I am getting some classes in Model Classes drop down but not my EF classes are there in list.
I have not done any refrencing to class library in my MVC project. Please guie me how and what where to do ?
Thanks
I believe you're referring to MVC Scaffolding
Install-Package MvcScaffolding
If it shows No Model Classes availble, when you hover it will give you a more verbose description:
If you get this message, cleaning and rebuilding should fix your problem.
Is your database project referenced by your main project? In your main project click references, add new reference - then in the projects tab select the name of the project with your edmx:
After that, clean and build!

crystal report datasource to business layer object colletion

In my project I want to use data source for a crystal report as collection of business layer object.
How do I do this? I have 3 projects together in my solution one of them is business object layer.
In grid and comboboxes or other controls I am able to bind these objects to the collection directly.
I know how to bind crystal report to the object collection when class is in the same project but not to the class which is in different project of current solution.
Thank you
May be its too late for you, but I'll post an answer, in the case that it helps others.
I had the same problem - where you cannot see the classes from other projects in .NET objects section of Crystal Report, but still you can add them.
Steps to add class as data source from other project:
Go to Database Expert
Click on Create new connection
Make new Connection form ADO.NET (XML)
In popup window add a full class name in the editable drop down
Click finish
Thats it ...

Applying Unity in dynamic menu

I was going through Unity 2.0 to check if it has an effective use in our new application. My application is a Windows Forms application and uses a traditional bar menu (at the top), currently.
My UIs (Windows Forms) more or less support Dependency Injection pattern since they all work with a class (Presentation Model Class) supplied to them via the constructor. The form then binds to the properties of the supplied P Model class and calls methods on the P Model class to perform its duties. Pretty simple and straightforward.
How P Model reacts to the UI actions and responds to them by co-ordinating with the Domain Class (Business Logic/Model) is irrelevant here and thus not mentioned.
The object creation sequence to show up one UI from menu then goes like this -
Create Business Model instance
Create Presentation Model instance with Business Model instance passed to P Model constructor.
Create UI instance with Presentation Model instance passed to UI constructor.
My present solution:
To show an UI in the method above from my menu I would have to refer all assemblies (Business, PModel, UI) from my Menu class. Considering I have split the modules into a number of physical assemblies, that would be a dificult task to add references to about 60 different assemblies. Also the approach is not very scalable since I would certainly need to release more modules and with this approach I would have to change the source code every time I release a new module.
So primarily to avoid the reference of so many assemblies from my Menu class (assembly) I did as below -
Stored all the dependency described above in a database table (SQL Server), e.g.
ModuleShortCode | BModelAssembly | BModelFullTypeName | PModelAssembly | PModelFullTypeName | UIAssembly | UIFullTypeName
Now used a static class named "Launcher" with a method "Launch" as below -
Launcher.Launch("Discount");
Launcher.Launch("Customers");
The Launcher internally uses data from the dependency table and uses Activator.CreateInstance() to create each of the objects and uses the instance as constructor parameter to the next object being created, till the UI is built. The UI is then shown as a modal dialog. The code inside Launcher is somewhat like -
Form frm = ResolveForm("Discount");
frm.ShowDialog();`
The ResolveForm does the trick of building the chain of objects.
Can Unity help me here?
Now when I did that I did not have enough information on Unity and now that I have studied Unity I think I have been doing more or less the same thing. So I tried to replace my code with Unity.
However, as soon as I started I hit a block. If I try to resolve UI forms in my Menu as
Form customers = myUnityContainer.Resolve<Customers>();
or
Form customers = myUnityContainer.Resolve(typeof(Customers));
Then either way, I need to refer to my UI assembly from my Menu assembly since the target Type "Customers" need to be known for Unity to resolve it. So I am back to same place since I would have to refer all UI assemblies from the Menu assembly. I understand that with Unity I would have to refer fewer assemblies (only UI assemblies) but those references are needed which defeats my objectives below -
Create the chain of objects dynamically without any assembly reference from Menu assembly. This is to avoid Menu source code changing every time I release a new module. My Menu also is built dynamically from a table.
Be able to supply new modules just by supplying the new assemblies and inserting the new Dependency row in the table by a database patch.
At this stage, I have a feeling that I have to do it the way I was doing, i.e. Activator.CreateInstance() to fulfil all my objectives. I need to verify whether the community thinks the same way as me or have a better suggestion to solve the problem.
The post is really long and I sincerely thank you if you come til this point. Waiting for your valuable suggestions.
Rajarshi
As I can see from this code
Form customers = myUnityContainer.Resolve<Customers>();
all your code need to know about the customer - is that it's a Form class. So if you use xml configuration for unity you can do the following:
<type type="Form" mapTo="Customer" name="Customer">
</type>
And then you'll be able to resolve it like this:
Form customers = myUnityContainer.Resolve<Form>("Customer");
and there is no need to refference your UI assembly. Offcourse it should be presented in the bin directory or GAC. In this case if you'll develop new Assembly - all you need is to change config and put in in bin or gac.
If you want to make unity configuration from db then you'll have to add referrence to your ui, becouse you'll have to call Register("Customer").

Resources