Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Confused in best implementation
Message
From
10/05/2014 03:40:04
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01599810
Message ID:
01599834
Views:
53
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I am trying to figure out the following problem.
>
>I have MiddlewareBase class. This is a base class for few other classes.
>
>It has the following constructor currently
>
>
>public class MiddlewareBase
>   {
>      public Request CurrentRequest;
>      public LocalIni iniFile;
>
>      private Database _database;
>      public Database database
>      {
>         get { return _database; }
>         set { _database = value; }
>      }
>      internal String CurrentSalespoint { get; private set; }
>      internal String CurrentOperator { get; private set; }
>      internal Int16 nPrefsSiteNo { get; set; }
>      internal Int16 nClientNumber { get; set; }
>
>      public static readonly DateTime DTSqlMinDate = DateTime.Parse("1900-01-01");
>
>      public static readonly String ServerName = "SalesEZ"; //"Siriusware.Middleware"; // used to be SalesEZ
>      public static readonly String GenericOperator = "SEZDTL"; // used in lcDTL in ValidatePass2
>
>      public MiddlewareBase()
>      {
>         iniFile = new LocalIni();
>      }
>
>I have several classes that inherit from this class.
>
>I don't want to set nPrefsSiteNo and nClientNumber properties in each of these classes individually. I want to set them once in the parent class. However, to get these properties I need to use this.database. methods.
>
>All instances of this class properly set up the database.
>
>My question is - how can I set these two properties in the base class?
>
>This is how I currently set nPrefsSiteNo in the instance class:
>
>
> this.nPrefsSiteNo = (Int16)database.GetPreferenceInt("prefs", "site_no");
>
>I want to move this logic into the base class. However, I can not call it in constructor as the database is not defined at that point.
>
>What can I do?
>
>Thanks in advance.

In addition to Viv's reply, you can get rid of the constructor here


>
>public class MiddlewareBase
>   {
>      public Request CurrentRequest;
>      public readonly LocalIni iniFile =  new LocalIni(); // here 

>
>      private Database _database;
>      public Database database
>      {
>         get { return _database; }
>         set { _database = value; }
>      }
>      internal String CurrentSalespoint { get; private set; }
>      internal String CurrentOperator { get; private set; }
>      internal Int16 nPrefsSiteNo { get; set; }
>      internal Int16 nClientNumber { get; set; }
>
>      public static readonly DateTime DTSqlMinDate = DateTime.Parse("1900-01-01");
>
>      public static readonly String ServerName = "SalesEZ"; //"Siriusware.Middleware"; // used to be SalesEZ
>      public static readonly String GenericOperator = "SEZDTL"; // used in lcDTL in ValidatePass2
>
>    //  public MiddlewareBase()
>     // {
>       //  iniFile = new LocalIni();
>     // }
>

And come to think of it, why not pass the database to the constructor


>
>public class MiddlewareBase
>   {
>      public Request CurrentRequest;
>      public readonly LocalIni iniFile =  new LocalIni(); // here 

>
>      private Database _database;
>      public Database database
>      {
>         get { return _database; }
>        private  set { _database = value; 
                             nPrefsSiteNo = (Int16)database.GetPreferenceInt("prefs", "site_no");
                            }
>      }
>      internal String CurrentSalespoint { get; private set; }
>      internal String CurrentOperator { get; private set; }
>      internal Int16 nPrefsSiteNo { get; set; }
>      internal Int16 nClientNumber { get; set; }
>
>      public static readonly DateTime DTSqlMinDate = DateTime.Parse("1900-01-01");
>
>      public static readonly String ServerName = "SalesEZ"; //"Siriusware.Middleware"; // used to be SalesEZ
>      public static readonly String GenericOperator = "SEZDTL"; // used in lcDTL in ValidatePass2
>
>      public MiddlewareBase( Database database)
>      {
                  this.database = database;

>     }
>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform