Guest User

Untitled

a guest
Jan 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. namespace FactoryMethod
  2. {
  3. public interface IConnectionProvider
  4. {
  5. string ConnectionString { get; }
  6. }
  7.  
  8. public class SqlServerConnection : IConnectionProvider
  9. {
  10. public string ConnectionString
  11. {
  12. get { return "Server=(local);initial catalog=AdventureWorks;Integrated Security=SSPI"; }
  13. }
  14. }
  15.  
  16. public class OracleConnection : IConnectionProvider
  17. {
  18. public string ConnectionString
  19. {
  20. get { return "User ID=vorleak;Password=vorleak;Data Source=localhost"; }
  21. }
  22. }
  23.  
  24. public class MySqlConnection : IConnectionProvider
  25. {
  26. public string ConnectionString
  27. {
  28. get { return "Database=AdventureWorks;Data Source=192.168.0.1;User Id=vorleak;Password=vorleak"; }
  29. }
  30. }
  31.  
  32. public class ConnectionProviderFactory
  33. {
  34. public IConnectionProvider CreateConnection(string type)
  35. {
  36. switch (type)
  37. {
  38. case "SQL Server" :
  39. return new SqlServerConnection();
  40. case "Oracle" :
  41. return new OracleConnection();
  42. case "MySQL":
  43. return new MySqlConnection();
  44. default:
  45. return null;
  46. }
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment