Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I like to create from my project 2 projects, were the code that is reusable for other projects is split off.
Visual Studio 2010 is able to handle one solution with mutiple projects, so this is in theory fine.

I just don't know what would be the best approach for my case:

For example i've a custom grid class (ucMyGrid)

Example of sub in the this custom class :
VB
Private Sub FillGrid(ByVal sSQL As String)
	
   Try
			
     'My code is here
			
   Catch ex As Exception
     mdlMyCustomLogging.fLOG(MDIParrent1.cUser.UserID, "ucMygrid => FillGrid: " & ex.Message.ToString)
   Finally
		
End Sub


The shared project contains the logging module 'mdlMyCustomLogging'


But how can i handle the userID that is used as a parameter in the logging?
Without passing this always as a parameter.

Thanks
Posted

Where is the userId coming from? Unless it is coming from some static resource, such the current logged on user, you can't get away from passing the value in some fashion to the component. If it is used by more methods in this component you could store it in a property of the class.
 
Share this answer
 
Comments
Homebunny 12-Jan-12 10:13am    
It isn't just the userID, there are lost more, but all already in classes.
I like the idea off storing these into a new class in the shared project.

But how can i access this class from other forms / modules in this shared project?
Before i could always access my -alwyas in memory- classes from the MDIParrent.
How can i access this class with stored parameters?
[no name] 12-Jan-12 11:31am    
How would you access the methods in this shared assembly? You would add a reference to the assembly into whatever project needed to use it. The parameters class would then be accessible also.

However, a more decoupled way would be to have another project/assembly that contained any entities used in both and share it between all projects.
Homebunny 12-Jan-12 16:50pm    
Thanks Mark, what i was missing were the shared classes, this article helped me alot: http://tutorials.freeskills.com/vb-net-programming-part-4-shared-or-class-members.htm. I'm happy now with the result.
If your class needs to refer to it's parent in any way (even to the extent of knowing it is an MDI Container) then it is difficult to divorce it sufficiently to separate it into a different project.

Ideally, a class should stand alone when you extract it, or with a bunch of related / interconnected classes in the same namespace.

If your control needs to know about the environment it is working in, it probably will need a lot of re-work to isolate it sufficiently - and may need a complete rewrite of some sections.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900