weird question #448
Replies: 3 comments 17 replies
-
Hi @KrzM, it really depends so much on what your needs and constraints are. It's not common for someone to use the console as their data entry point for the database, but it can make sense in some cases. If you use the console, making it intuitive for users is a lot of extra work, but maybe you don't need that if it's just for you. Using aspnet minimal apis can also be a low effort way to build an application to take data. It all depends on how you want to save and read the data. Have you tried asking questions on a site like stackoverflow? you can use tags like below and there are people who are giddy with excitement to offer help for this kind of stuff.
Reddit can be another good resource I'd recommend posting across a few sites and see which ones give you the most useful feedback. |
Beta Was this translation helpful? Give feedback.
-
I am chill testing to make sure it works before using runtime
|
Beta Was this translation helpful? Give feedback.
-
Hi @KrzM We talked a while back about how to make a simpler cli for CRUD operations. I saw you created a new one recently (it showed up as a in our list of github repos using CommandDotNet) and thought I'd throw together a quick suggestion on a way to structure the app that would be simpler, with less layers of indirection. With this app, you would just need an implementation of IRepository to register. You could use a tool like AutoMapper or Mapster to auto-map the IArgumentModels to the classes you save to the database. I think this will make your apps simpler to maintain and easier for others to grok when you get to the point of showing off your work. public class Program
{
public static void Main(string[] args)
{
IServiceProvider services = new ServiceCollection()
.AddSingleton<Crud<Album>>()
.AddSingleton<Crud<Song>>()
.BuildServiceProvider();
new AppRunner<Program>()
.UseNameCasing(Case.KebabCase)
.UseMicrosoftDependencyInjection(services)
.Run(args);
}
[Subcommand(RenameAs = "albums")]
public Crud<Album> Albums { get; set; }
[Subcommand(RenameAs = "songs")]
public Crud<Song> Songs { get; set; }
}
public class Crud<T> where T: IArgumentModel
{
private readonly IRepository<T> _repository;
public Crud(IRepository<T> repository) =>
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
public void Create(IConsole console, T model)
{
console.WriteLine($"Creating {model}");
_repository.Add(model);
}
public void Update(IConsole console, T model)
{
console.WriteLine($"Updating {model}");
_repository.Update(model);
}
public void Delete(IConsole console, string name)
{
console.WriteLine($"Deleting {name}");
_repository.Delete(name);
}
public void Read(IConsole console, string name)
{
console.WriteLine(_repository.Get(name));
}
public void List(IConsole console)
{
foreach (var model in _repository.GetAll())
{
console.WriteLine(model);
}
}
}
public class Album : IArgumentModel
{
[Operand]
public string Name { get; set; }
public override string ToString()
{
return $"Album: {Name}";
}
}
public class Song : IArgumentModel
{
[Operand]
public string Album { get; set; }
[Operand]
public string Name { get; set; }
public override string ToString()
{
return $"Song: {Album} - {Name}";
}
}
public class IRepository<T>
{
public virtual IEnumerable<T> GetAll() => throw new NotImplementedException();
public virtual T Get(string id) => throw new NotImplementedException();
public virtual void Add(T entity) => throw new NotImplementedException();
public virtual void Update(T entity) => throw new NotImplementedException();
public virtual void Delete(string id) => throw new NotImplementedException();
} Hope this is helpful. Cheers, |
Beta Was this translation helpful? Give feedback.
-
Hi @drewburlingame
I have weird question, but you are only guy i have contact to, i can even ask it.
I want to have database with list/info on my stuff, things i own.
I think i will do single table ef core code first.
Then i will copy cli app templete i worked out, with commandDotNet.
This shuld take one day, with test and first data in.
It seems best bet to make it work for me.
Is there faster solution i am missing ?
I dont want plain sql or excel, it seems to be layer i can avoid.
Beta Was this translation helpful? Give feedback.
All reactions