I'm creating a password encrypter and I'm using dependency injection, but somehow this error comes when running the program.
System.InvalidOperationException: "Unable to resolve service for type 'System.Windows.Forms.TextBox' while attempting to activate 'encryptPasswort.EncryptionProcedureService'."
public class EncryptionProcedureService: IVerschlüsselungsVerfahrenService
{
public string Passwort { get; set; }
public string MasterKey { get; set; }
public EncryptionProcedureService(TextBox passwortEingabe, TextBox masterKey)
{
Passwort = passwortEingabe.Text;
MasterKey = masterKey.Text;
}
public string encryptPasswort()
{
string encryptedPasswort = "";
StringBuilder passwortReader = new StringBuilder(Passwort);
StringBuilder masterKeyReader = new StringBuilder(MasterKey);
for (int i = 0; i < passwortReader.Length; i++)
{
for (int j = masterKeyReader.Length; j > 0; j--)
{
passwortReader[i] = masterKeyReader[j];
encryptedPasswort += passwortReader[i];
}
}
return encryptedPasswort;
}
}
public static class Program
{
[STAThread]
static void Main()
{
var serviceProvider = new ServiceCollection()
.AddSingleton<IMainForm, MainForm>()
.AddSingleton<IEncryptionProcedureService, EncryptionProcedureService>()
.BuildServiceProvider();
ApplicationConfiguration.Initialize();
var encryptionProcedureService = serviceProvider.GetRequiredService<IEncryptionProcedureService>();
var form1 = new MainForm(EncryptionProcedureService);
Application.Run(form1);
}
}