Can not use the BLL I created - c#

I have 2 projects in this app. One of this is supposed to make the connection with the database.
I am trying to add the methods from the BLL project to the MVC_BO. I already added the reference, but when I try the "using BLL" the MVC_BO does not recognize the reference.
Both files in BLL project are using namespace BLL (as you can see in the image below)
enter image description here

Your classes are not public, so nothing is being exported from that namespace. Make your classes public. They are internal by default.

Related

IDesign AddDbContext with an interface?

I am trying to create a new asp.net core web application using Razor pages. I want to add my db context in the startup.cs file, but I am using something called IDesign.
My DbContext entity is in a project that I am not allowed to reference. I need to somehow add my context either at the accessor layer or something else. I'm not super familiar with how services work for .net core.
I have a solution set up like this:
Clients Project
The project with the cshtml files, startupcs and all of that is here
Can only reference managers and utilities projects
Managers Project
Used for chaining calls to engines/accessors to accomplish tasks at a high level
Used to make calls to accessors
Can only reference accessors, engines, and utilities project
Engines Project
Used for business logic
Can only reference the accessors and utilities projects
Accessors Project
resource accessors. Hits dbs/services.
This is where my dbcontext class lives
can't reference anything except for utilities
Utilities Project
Used to store global classes and utility functions that apply to all projects
Can't reference anything
My problem is that if my DbContext lives in the accessors project, how do I pass that up from the managers so that I can use it in the clients? Has anyone had experience with this before?
Just to reiterate, I know that I could easily reference accessors project in the clients project and use the dbcontext from there. My problem is that I want to avoid being able to reference accessors so that other people who are working with this code aren't able to see any accessors classes.
You can add the DbContext related classes in a new project without the parts of the "Accessors" project. It will be similar to the "Utilities" project, which can be used/referenced by all projects. This way your "Clients" project knows what a DbContext object is and how to use it, but it doesn't know how to get one (unless it has a connection string and connects to the database directly using the DbContext class). This would be the responsible of the "Managers" or "Accessors" project.
The references chain will look like this:

class access modifier in C#

I know it's a very basic questions but I'm just a newbie in C#. I know the default access modifier for class in C# is "internal" which means available in the same assembly. But let's say I have two public(more accessibility) class Employee and Departments in models, so they don't need to reference each other, fair enough. But I also a DepartmentController and EmployeeController in the controllers, and I need to reference class Employee and Departments, but aren't DepartmentController, EmployeeController Employee and Departments in the same assembly which is the project name?
This is the picture of the program:
You need to reference those classes because they aren't in the same namespace (MVCDemo. Controller!= MVCDemo. Models). If you import those classes to the scope of another project by importing their assembly, you are going to be able to see only the public classes, not the internals. I highly recommend that you try to move the models to a Class Library Project and play with their access modifiers to understand their scope implication better (Like trying to import an internal class withing another assembly).
Yes, your solution has a single project, and there's a single assembly for your project.
The reason why the you need public access modifiers on your controllers is explained here...
Why does the ASP.NET MVC Controller class need to be public?
Basically the MVC framework you're referencing needs access to the controllers in order for them to be used by the framework, if they're internal the MVC framework would not be able to access your controllers.
Whilst there's a single project in your solution, you're referencing many other assemblies. Anything within a project that needs to be accessed by another assembly, be it an assembly created from one of your projects or an assembly you're referencing, needs to have the Public access modifier.

Creating C# DLL, what am I doing wrong?

A little background: I'm writing a set of C# classes to wrap a SOAP connector to another system called Jira. The SOAP connector which Jira exposes has too many functions for my purposes, so I'm attempting to simplify the interface.
My setup: In C#/Visual Studio 2010, my solution is laid out as follows:
JiraService
Properties/
AssemblyInfo.cs
Settings.settings/
References/
...
System.Web.Services
Web References
devjira.soap /* my connector to the jira soap reference i'm wrapping */
Types/ /* these are data classes i'm trying to expose for the user */
Comment.cs
Issue.cs
Project.cs
User.cs
app.config
Jira.cs /* main class I'm trying to provide to user */
Jira.cs is in the JiraService namespace. Comment.cs, Issue.cs, Project.cs, and User.cs are all in the JiraService.Types namespace. Jira.cs essentially exposes a few methods which either take or return the classes found in the Types directory. Under the properties I have the Default namespace set to JiraService and the Output type set to Class Library.
My Problem: When I build the solution I get out JiraService.dll. When I add this reference to another project, the Jira, Comment, Issue, Project, and User classes are not in the JiraService or JiraService.Types namespaces of the included .dll. The only available namespace is JiraService.devjira.soap, which is the library I'm trying to simplify and hide! What am I doing wrong? Why are my classes not showing up in the final library?
Thanks for all your help!
Need to see code to tell for sure, but a few things to check;
1. Did you name your namespaces correctly in all the classes? Folder structure doesn't matter, its the namespace attribute that counts.
2. Are your classes public?
Beyond that, post some sample code please..

Adding WCF Service Reference doesn't generate code

Scenario:
Web Site project under .NET 3.5
Visual Studio 2010
WCF Service reference
Problem:
I'm trying to extend a class marked with the DataContract attribute. I though the generated class was declared partial, so that i could easily extend it. I tried declaring a partial class within the same namespace with the same name, but it doesn't seem to recognize what class it's extending. I tried locating the generated code file (Reference.cs) which i thought existed after reading this article inside the reference folder, but it wasn't there. When trying to navigate to the class's definition, i found out it was in a compiled library, and the biggest problem is that it wasn't declared as partial.
Question:
Is this difference related to the fact that i'm using a Web Site and not a Web Project?
If so, is there a way that i could make the code generator (which also seems to compile the generated code) to declare class as partial?
Yes there is a way you can declare your DataContract classes as Partial.
For this you'd want to use the DTO pattern. Basically this means defining "shared" Classes in a different assembly, and having both the Service, and the App which consumes the Service, both reference the assembly with your common classes.
So for example your "DTOs" assembly might contain a DTO called "Product". Ok, so you make them Partial, and next you decorate Product, and which ever other Class with the WCF attributes, like DataContract, and DataMember etc.
Now, you reference you DTO assembly with you Service project, and your Web Project.
Now, when you go to your web project and click on "Add Service Reference", click on the "Advanced", and you'll notice you can enable an option to "resuse referenced assemblies". do that and you'll have full control over you DataContracts.
Empty client reference proxy classes can indeed be a most frustrating problem to solve.
I would recommend that you use the WCF Test Client or command line svcutil.exe. against the service - you can often get a much more detailed error description with these tools than with Visual Studio service reference wizard.
In my case the issues are invariably related to serialization or namespacing issues of the entity / graph - typically mismatched get and set on DataMember properties, missing KnownType on polymorphic entities, or circular references in the graph.
Partial shouldn't be a problem. Just make sure that any additional properties that you want serialized are marked as DataMember.
If all else fails, would recommend that you run a serialization / deserialization unit test against your entity / entity graph.

Problem sharing domain model between WCF and Silverlight Project

I am writing a Large Scale Silverlight Application.
I am currently writing the data retrieval elements.
I have now encoutered and issue.
I have a common Project that hold objects, this project is referenced by both the UI and the WCF service.
The UI requires INotifyPropertyChanged for binding purposes.
Now the WCF must use the same objects, but I am getting a compiler error saying
"The type
'System.ComponentModel.INotifyPropertyChanged'
is defined in an assembly that is not
referenced."
EDIT: The error is in the WCF service.
I want one object class, how do I solve this problem?
diagram http://www.pcbuyersguide.co.za/picture.php?albumid=19&pictureid=1708
Thanks
-Oliver
If you plan to use the same source code for your Entities (domain) for both a clr and silverlight project you will need to use 2 projects because the Silverlight assemblies are not the same as CLR assemblies.
Add a Silverlight Class Library project to your solution, the name is not important but I usually just use XXXX_SL.
Now, you will 'Add Existing Item' all of the source files from the clr project, but notice the dropdown on the open or select button? click that and 'add as link' or whatever it says there.
You are now using the same source for both projects and your solution will compile.
There may be some minor tweaks along the way but that will set you on the right path..
Here is some reference material
did you add a reference in the compiling project to System.ComponentModel
I found a method here that allows one to create the CLR classes on the service side and then one can use the generated objects from the Service Reference as the classes are generated with the INotifyPropertyChanged and ObservableCollection.
This solves the immediate problem of the client/server boundary but does fit into my solution because in order to use the generated objects you need the service reference. But I have a ProxyClass that does the talking to WCF so there I cannot see a way of passing these object types back to the ViewModel.
I see some people have written mapper classes, but this is far from ideal as I would have to write 3 classes for each POCO object (client class, server DTO class, mapper).
Any more suggestions?

Categories

Resources