Note that there are some explanatory texts on larger screens.

plurals
  1. PODataProvider Switch / Singleton ?
    primarykey
    data
    text
    <p>I have a website and want to step over from MySql to SqlServer. </p> <p>In my website I use a BE layer (Business Entities), BLL (Business Logic Layer), DAL (Data Access Layer), and of course a Web Layer (Website) </p> <p>I've created a switch in the web.config (app settings) to tell the website to use MySql or SqlServer as DataProvider. </p> <p>I use the folowing code.... which works perfectly, but my question is ... </p> <ul> <li>Is this the right way to use a multi DAL tier?</li> <li>Is this thread Safe ? or I have to implement Singleton at the Factory class ?</li> </ul> <p>Please let me know what you should do, or what your opionion is.</p> <pre><code>namespace MyNameSpace.BE { public class Product { public int Id { get; set; } public int Description { get; set; } } } namespace MyNameSpace.DAL.Base { public abstract class ProductManager { public abstract List&lt;Product&gt; GetProductList(); } } namespace MyNameSpace.DAL.MySql { public class ProductManager : Base.ProductManager { public override List&lt;Product&gt; GetProductList() { return new List&lt;Product&gt;(); } } } namespace MyNameSpace.DAL.SqlServer { public class ProductManager : Base.ProductManager { public override List&lt;Product&gt; GetProductList() { return new List&lt;Product&gt;(); } } } namespace MyNameSpace.Bll { /// do I have to use Singleton here ?? or not ? public static class Factory { private static ProductManager CreateProductManager() { if (Config.Settings.Switches.DataProvider == DataProvider.MySql) { return new DAL.MySql.ProductManager(); } else if (Config.Settings.Switches.DataProvider == DataProvider.SqlServer) { return new DAL.SqlServer.ProductManager(); } return null; } private static ProductManager _ProductManager; public static ProductManager ProductManager { get { if (_ProductManager == null) { _ProductManager = CreateProductManager(); } return _ProductManager; } } } } /// &lt;summary&gt; /// for example ASP.NET page /// &lt;/summary&gt; class MyPage { public MyPage() { List&lt;Product&gt; productList = Factory.ProductManager.GetProductList(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload