Avoid SRP violation in Console application [closed]
up vote
-1
down vote
favorite
I'm developing a simple Console application. Program.cs initialize dependency injection, set file names, accept inputs and print the result.
I got a note that my Program.cs violates the SRP principle ,Program.cs must accept the inputs and print the results, must initialize dependencies. I don't know how to fix that, please advice.
using Autofac;
using Mynamespace.Core;
using Mynamespace.Core.Interfaces;
using Mynamespace.InfraSturcture;
using Mynamespace.Services;
using System;
using System.Collections.Generic;
namespace Mynamespace
{
internal class Program
{
private static IProcessTransactions _processTransactions;
private static IGetTransaction _getTransaction;
private static IApplyBusinessRoles _applyBusinessRoles;
private static List<string> lstMerchantName = new List<string>();
private static void Main()
{
try
{
const string filename = "Transactions.txt";
InjectDependicies();
SetFileName(filename);
var transactionsCount = _getTransaction.GetTransactionsCount();
if (transactionsCount <= 0) return;
while (true)
{
Console.WriteLine("User Id:1 or 2 or 3 or 4 or 5");
Console.WriteLine("To End The Program Type Exit");
Console.WriteLine("Enter User Id:");
var input = Console.ReadLine();
if (input?.ToLower() == "exit")
break;
if (!Helper.ValidateInput(input))
continue;
DisplayRawTransactions(transactionsCount);
if (input != null)
DisplayProcessedTransaction(transactionsCount, int.Parse(input));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void SetFileName(string filename)
{
_processTransactions.FileName = filename;
_getTransaction.FileName = filename;
}
private static void InjectDependicies()
{
var container = AutoFacBootstrapper.Init();
container.Resolve<IReadTransactionFromFile>();
container.Resolve<IGetClients>();
container.Resolve<IGetUsers>();
container.Resolve<IGeBusinessRoles>();
_getTransaction = container.Resolve<IGetTransaction>();
_processTransactions = container.Resolve<IProcessTransactions>();
_applyBusinessRoles = container.Resolve<IApplyBusinessRoles>();
}
private static void DisplayRawTransactions(int transactionsCount)
{
WriteHeaders("Raw");
for (var i = 0; i < transactionsCount; i++)
{
var rawTransaction = GetRawTransaction(i);
DisplayTransactions(rawTransaction.TransacionDate,
rawTransaction.MerchantName,
rawTransaction.Amount.ToString("F"));
}
}
private static Transaction GetRawTransaction(int i)
{
var rawTransaction = _getTransaction.GetSingleTransaction(i);
lstMerchantName?.Add(rawTransaction.MerchantName);
return rawTransaction;
}
private static void DisplayProcessedTransaction(int transactionsCount, int userId)
{
WriteHeaders("Processed");
for (var i = 0; i < transactionsCount; i++)
{
var processedTransaction = GetProcessedTransaction(userId, i);
DisplayTransactions(processedTransaction.TransacionDate,
processedTransaction.MerchantName,
processedTransaction.Fees.ToString("F"));
}
}
private static TransactionResult GetProcessedTransaction(int userId, int transactionIndex)
{
return _processTransactions.GetProcessedTransaction(transactionIndex,
_applyBusinessRoles.ApplyFees(userId, lstMerchantName[transactionIndex]));
}
private static void WriteHeaders(string transactionType)
{
Console.WriteLine("+++++ " + transactionType + " Transactions Data +++++");
Console.WriteLine("{0}t{1}t{2}", "Date", "Merchant Name",
transactionType == "Processed" ? "Fees" : "Amount");
Console.WriteLine("----------------------------");
}
private static void DisplayTransactions(DateTime transactionDate, string merchantName, string money)
{
if (money != null)
{
Console.WriteLine("{0}t{1}t{2}",
transactionDate.ToString("yyyy-MM-dd"),
merchantName,
money);
}
}
}
}
c# console
closed as unclear what you're asking by 200_success, t3chb0t, Zeta, Heslacher, Graipher Dec 11 at 13:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-1
down vote
favorite
I'm developing a simple Console application. Program.cs initialize dependency injection, set file names, accept inputs and print the result.
I got a note that my Program.cs violates the SRP principle ,Program.cs must accept the inputs and print the results, must initialize dependencies. I don't know how to fix that, please advice.
using Autofac;
using Mynamespace.Core;
using Mynamespace.Core.Interfaces;
using Mynamespace.InfraSturcture;
using Mynamespace.Services;
using System;
using System.Collections.Generic;
namespace Mynamespace
{
internal class Program
{
private static IProcessTransactions _processTransactions;
private static IGetTransaction _getTransaction;
private static IApplyBusinessRoles _applyBusinessRoles;
private static List<string> lstMerchantName = new List<string>();
private static void Main()
{
try
{
const string filename = "Transactions.txt";
InjectDependicies();
SetFileName(filename);
var transactionsCount = _getTransaction.GetTransactionsCount();
if (transactionsCount <= 0) return;
while (true)
{
Console.WriteLine("User Id:1 or 2 or 3 or 4 or 5");
Console.WriteLine("To End The Program Type Exit");
Console.WriteLine("Enter User Id:");
var input = Console.ReadLine();
if (input?.ToLower() == "exit")
break;
if (!Helper.ValidateInput(input))
continue;
DisplayRawTransactions(transactionsCount);
if (input != null)
DisplayProcessedTransaction(transactionsCount, int.Parse(input));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void SetFileName(string filename)
{
_processTransactions.FileName = filename;
_getTransaction.FileName = filename;
}
private static void InjectDependicies()
{
var container = AutoFacBootstrapper.Init();
container.Resolve<IReadTransactionFromFile>();
container.Resolve<IGetClients>();
container.Resolve<IGetUsers>();
container.Resolve<IGeBusinessRoles>();
_getTransaction = container.Resolve<IGetTransaction>();
_processTransactions = container.Resolve<IProcessTransactions>();
_applyBusinessRoles = container.Resolve<IApplyBusinessRoles>();
}
private static void DisplayRawTransactions(int transactionsCount)
{
WriteHeaders("Raw");
for (var i = 0; i < transactionsCount; i++)
{
var rawTransaction = GetRawTransaction(i);
DisplayTransactions(rawTransaction.TransacionDate,
rawTransaction.MerchantName,
rawTransaction.Amount.ToString("F"));
}
}
private static Transaction GetRawTransaction(int i)
{
var rawTransaction = _getTransaction.GetSingleTransaction(i);
lstMerchantName?.Add(rawTransaction.MerchantName);
return rawTransaction;
}
private static void DisplayProcessedTransaction(int transactionsCount, int userId)
{
WriteHeaders("Processed");
for (var i = 0; i < transactionsCount; i++)
{
var processedTransaction = GetProcessedTransaction(userId, i);
DisplayTransactions(processedTransaction.TransacionDate,
processedTransaction.MerchantName,
processedTransaction.Fees.ToString("F"));
}
}
private static TransactionResult GetProcessedTransaction(int userId, int transactionIndex)
{
return _processTransactions.GetProcessedTransaction(transactionIndex,
_applyBusinessRoles.ApplyFees(userId, lstMerchantName[transactionIndex]));
}
private static void WriteHeaders(string transactionType)
{
Console.WriteLine("+++++ " + transactionType + " Transactions Data +++++");
Console.WriteLine("{0}t{1}t{2}", "Date", "Merchant Name",
transactionType == "Processed" ? "Fees" : "Amount");
Console.WriteLine("----------------------------");
}
private static void DisplayTransactions(DateTime transactionDate, string merchantName, string money)
{
if (money != null)
{
Console.WriteLine("{0}t{1}t{2}",
transactionDate.ToString("yyyy-MM-dd"),
merchantName,
money);
}
}
}
}
c# console
closed as unclear what you're asking by 200_success, t3chb0t, Zeta, Heslacher, Graipher Dec 11 at 13:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
3
Welcome to Code Review. Could you clarify, does this code produce the right output or not? It's hard for us to tell what's going on, because it calls code that you haven't shown us.
– 200_success
Dec 11 at 0:18
Yes, it works fine and gives the right results, there are other classes which I did not write their code. The problem is SRP violation.
– Daina Hodges
Dec 11 at 16:02
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm developing a simple Console application. Program.cs initialize dependency injection, set file names, accept inputs and print the result.
I got a note that my Program.cs violates the SRP principle ,Program.cs must accept the inputs and print the results, must initialize dependencies. I don't know how to fix that, please advice.
using Autofac;
using Mynamespace.Core;
using Mynamespace.Core.Interfaces;
using Mynamespace.InfraSturcture;
using Mynamespace.Services;
using System;
using System.Collections.Generic;
namespace Mynamespace
{
internal class Program
{
private static IProcessTransactions _processTransactions;
private static IGetTransaction _getTransaction;
private static IApplyBusinessRoles _applyBusinessRoles;
private static List<string> lstMerchantName = new List<string>();
private static void Main()
{
try
{
const string filename = "Transactions.txt";
InjectDependicies();
SetFileName(filename);
var transactionsCount = _getTransaction.GetTransactionsCount();
if (transactionsCount <= 0) return;
while (true)
{
Console.WriteLine("User Id:1 or 2 or 3 or 4 or 5");
Console.WriteLine("To End The Program Type Exit");
Console.WriteLine("Enter User Id:");
var input = Console.ReadLine();
if (input?.ToLower() == "exit")
break;
if (!Helper.ValidateInput(input))
continue;
DisplayRawTransactions(transactionsCount);
if (input != null)
DisplayProcessedTransaction(transactionsCount, int.Parse(input));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void SetFileName(string filename)
{
_processTransactions.FileName = filename;
_getTransaction.FileName = filename;
}
private static void InjectDependicies()
{
var container = AutoFacBootstrapper.Init();
container.Resolve<IReadTransactionFromFile>();
container.Resolve<IGetClients>();
container.Resolve<IGetUsers>();
container.Resolve<IGeBusinessRoles>();
_getTransaction = container.Resolve<IGetTransaction>();
_processTransactions = container.Resolve<IProcessTransactions>();
_applyBusinessRoles = container.Resolve<IApplyBusinessRoles>();
}
private static void DisplayRawTransactions(int transactionsCount)
{
WriteHeaders("Raw");
for (var i = 0; i < transactionsCount; i++)
{
var rawTransaction = GetRawTransaction(i);
DisplayTransactions(rawTransaction.TransacionDate,
rawTransaction.MerchantName,
rawTransaction.Amount.ToString("F"));
}
}
private static Transaction GetRawTransaction(int i)
{
var rawTransaction = _getTransaction.GetSingleTransaction(i);
lstMerchantName?.Add(rawTransaction.MerchantName);
return rawTransaction;
}
private static void DisplayProcessedTransaction(int transactionsCount, int userId)
{
WriteHeaders("Processed");
for (var i = 0; i < transactionsCount; i++)
{
var processedTransaction = GetProcessedTransaction(userId, i);
DisplayTransactions(processedTransaction.TransacionDate,
processedTransaction.MerchantName,
processedTransaction.Fees.ToString("F"));
}
}
private static TransactionResult GetProcessedTransaction(int userId, int transactionIndex)
{
return _processTransactions.GetProcessedTransaction(transactionIndex,
_applyBusinessRoles.ApplyFees(userId, lstMerchantName[transactionIndex]));
}
private static void WriteHeaders(string transactionType)
{
Console.WriteLine("+++++ " + transactionType + " Transactions Data +++++");
Console.WriteLine("{0}t{1}t{2}", "Date", "Merchant Name",
transactionType == "Processed" ? "Fees" : "Amount");
Console.WriteLine("----------------------------");
}
private static void DisplayTransactions(DateTime transactionDate, string merchantName, string money)
{
if (money != null)
{
Console.WriteLine("{0}t{1}t{2}",
transactionDate.ToString("yyyy-MM-dd"),
merchantName,
money);
}
}
}
}
c# console
I'm developing a simple Console application. Program.cs initialize dependency injection, set file names, accept inputs and print the result.
I got a note that my Program.cs violates the SRP principle ,Program.cs must accept the inputs and print the results, must initialize dependencies. I don't know how to fix that, please advice.
using Autofac;
using Mynamespace.Core;
using Mynamespace.Core.Interfaces;
using Mynamespace.InfraSturcture;
using Mynamespace.Services;
using System;
using System.Collections.Generic;
namespace Mynamespace
{
internal class Program
{
private static IProcessTransactions _processTransactions;
private static IGetTransaction _getTransaction;
private static IApplyBusinessRoles _applyBusinessRoles;
private static List<string> lstMerchantName = new List<string>();
private static void Main()
{
try
{
const string filename = "Transactions.txt";
InjectDependicies();
SetFileName(filename);
var transactionsCount = _getTransaction.GetTransactionsCount();
if (transactionsCount <= 0) return;
while (true)
{
Console.WriteLine("User Id:1 or 2 or 3 or 4 or 5");
Console.WriteLine("To End The Program Type Exit");
Console.WriteLine("Enter User Id:");
var input = Console.ReadLine();
if (input?.ToLower() == "exit")
break;
if (!Helper.ValidateInput(input))
continue;
DisplayRawTransactions(transactionsCount);
if (input != null)
DisplayProcessedTransaction(transactionsCount, int.Parse(input));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void SetFileName(string filename)
{
_processTransactions.FileName = filename;
_getTransaction.FileName = filename;
}
private static void InjectDependicies()
{
var container = AutoFacBootstrapper.Init();
container.Resolve<IReadTransactionFromFile>();
container.Resolve<IGetClients>();
container.Resolve<IGetUsers>();
container.Resolve<IGeBusinessRoles>();
_getTransaction = container.Resolve<IGetTransaction>();
_processTransactions = container.Resolve<IProcessTransactions>();
_applyBusinessRoles = container.Resolve<IApplyBusinessRoles>();
}
private static void DisplayRawTransactions(int transactionsCount)
{
WriteHeaders("Raw");
for (var i = 0; i < transactionsCount; i++)
{
var rawTransaction = GetRawTransaction(i);
DisplayTransactions(rawTransaction.TransacionDate,
rawTransaction.MerchantName,
rawTransaction.Amount.ToString("F"));
}
}
private static Transaction GetRawTransaction(int i)
{
var rawTransaction = _getTransaction.GetSingleTransaction(i);
lstMerchantName?.Add(rawTransaction.MerchantName);
return rawTransaction;
}
private static void DisplayProcessedTransaction(int transactionsCount, int userId)
{
WriteHeaders("Processed");
for (var i = 0; i < transactionsCount; i++)
{
var processedTransaction = GetProcessedTransaction(userId, i);
DisplayTransactions(processedTransaction.TransacionDate,
processedTransaction.MerchantName,
processedTransaction.Fees.ToString("F"));
}
}
private static TransactionResult GetProcessedTransaction(int userId, int transactionIndex)
{
return _processTransactions.GetProcessedTransaction(transactionIndex,
_applyBusinessRoles.ApplyFees(userId, lstMerchantName[transactionIndex]));
}
private static void WriteHeaders(string transactionType)
{
Console.WriteLine("+++++ " + transactionType + " Transactions Data +++++");
Console.WriteLine("{0}t{1}t{2}", "Date", "Merchant Name",
transactionType == "Processed" ? "Fees" : "Amount");
Console.WriteLine("----------------------------");
}
private static void DisplayTransactions(DateTime transactionDate, string merchantName, string money)
{
if (money != null)
{
Console.WriteLine("{0}t{1}t{2}",
transactionDate.ToString("yyyy-MM-dd"),
merchantName,
money);
}
}
}
}
c# console
c# console
asked Dec 10 at 19:14
Daina Hodges
12
12
closed as unclear what you're asking by 200_success, t3chb0t, Zeta, Heslacher, Graipher Dec 11 at 13:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by 200_success, t3chb0t, Zeta, Heslacher, Graipher Dec 11 at 13:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
3
Welcome to Code Review. Could you clarify, does this code produce the right output or not? It's hard for us to tell what's going on, because it calls code that you haven't shown us.
– 200_success
Dec 11 at 0:18
Yes, it works fine and gives the right results, there are other classes which I did not write their code. The problem is SRP violation.
– Daina Hodges
Dec 11 at 16:02
add a comment |
3
Welcome to Code Review. Could you clarify, does this code produce the right output or not? It's hard for us to tell what's going on, because it calls code that you haven't shown us.
– 200_success
Dec 11 at 0:18
Yes, it works fine and gives the right results, there are other classes which I did not write their code. The problem is SRP violation.
– Daina Hodges
Dec 11 at 16:02
3
3
Welcome to Code Review. Could you clarify, does this code produce the right output or not? It's hard for us to tell what's going on, because it calls code that you haven't shown us.
– 200_success
Dec 11 at 0:18
Welcome to Code Review. Could you clarify, does this code produce the right output or not? It's hard for us to tell what's going on, because it calls code that you haven't shown us.
– 200_success
Dec 11 at 0:18
Yes, it works fine and gives the right results, there are other classes which I did not write their code. The problem is SRP violation.
– Daina Hodges
Dec 11 at 16:02
Yes, it works fine and gives the right results, there are other classes which I did not write their code. The problem is SRP violation.
– Daina Hodges
Dec 11 at 16:02
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
3
Welcome to Code Review. Could you clarify, does this code produce the right output or not? It's hard for us to tell what's going on, because it calls code that you haven't shown us.
– 200_success
Dec 11 at 0:18
Yes, it works fine and gives the right results, there are other classes which I did not write their code. The problem is SRP violation.
– Daina Hodges
Dec 11 at 16:02