Jacko
Jacko
Explore posts from servers
CC#
Created by Jacko on 2/3/2025 in #help
Question about Dependency Injection:
I’m currently using autofac for dependency injection in a project because I’m attempting to do a plugin architecture and it has some features for loading interfaces from dlls. I came across the Microsoft dependency injection library and learned that it can load from autofac containers with the extension. What’s the benefit of this over using autofac alone ?
66 replies
CC#
Created by Jacko on 2/1/2025 in #help
✅ Can custom attributes use interfaces somehow ?
I have an interface named IConfiguration and I'm wondering is it possible to write a custom attribute so I can do [StaticConfiguration("Key"]var settings: Settings so that the StaticConfiguration attribute will get the config for that key from IConfiguration and parse it into the type Settings?
13 replies
CC#
Created by Jacko on 1/31/2025 in #help
How to configure services in my cli application:
var container = new ContainerBuilder()
.WithSystemConfiguration()
.WithConsoleVerbosityWriter()
.WithSystemServices()
.WithPlugins();
var container = new ContainerBuilder()
.WithSystemConfiguration()
.WithConsoleVerbosityWriter()
.WithSystemServices()
.WithPlugins();
So I have code like above where I'm creating a container using autofac and then registering some services with methods like
public static ContainerBuilder WithConsoleVerbosityWriter(this ContainerBuilder container)
{
var logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} {SourceContext:l} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
container.RegisterInstance(logger).As<ILogger>();
return container;
}
public static ContainerBuilder WithConsoleVerbosityWriter(this ContainerBuilder container)
{
var logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} {SourceContext:l} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
container.RegisterInstance(logger).As<ILogger>();
return container;
}
The issue is I want the logger to get its configuration details from the IConfiguraton supplied by WithSystemConfiguration() and I'm not sure whether to use a build callback like
{
container.RegisterBuildCallback(scope =>
{
var config = scope.Resolve<IConfiguration>();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(config)
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} {SourceContext:l} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();

Log.Logger = logger; // Set the static Serilog logger
scope.Resolve<ILoggerFactory>().AddSerilog(logger); // Add Serilog to ILoggerFactory

{
container.RegisterBuildCallback(scope =>
{
var config = scope.Resolve<IConfiguration>();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(config)
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} {SourceContext:l} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();

Log.Logger = logger; // Set the static Serilog logger
scope.Resolve<ILoggerFactory>().AddSerilog(logger); // Add Serilog to ILoggerFactory

or create a wrapper class like MyCustomLogger that uses ILogger and IConfiguration in it's constructor
15 replies
CC#
Created by Jacko on 1/28/2025 in #help
Configuring a spectre cli app:
What’s the best way to configure a cli app to have a config file users can modify to customise parts of the application such as connection strings ?
8 replies
CC#
Created by Jacko on 1/26/2025 in #help
Get information about DI container:
So I’ve read that it’s a bad idea to pass a DI container into a class and use .get() because it’s a service locator pattern which isn’t recommended. I’m trying to make a cli with a plugin system and as part of that I want to have a debug command that returns all the registered plugins from the di container. Is there a best practice way to do this using Autofac ? I want to have a class like ContainerService which has some methods to get registered services, find their file locations etc.
5 replies
CC#
Created by Jacko on 1/24/2025 in #help
Restrict loaded assemblies:
I’m writing a console app with a plugin system, for security I want to try restrict it to assemblies that don’t use certain namespaces like system IO with the intention being they have to request stuff like input and config values through interfaces. Is this possible and how do I check what namespaces an assembly uses ?
11 replies
CC#
Created by Jacko on 1/7/2025 in #help
Properties vs constructor:
I’m currently creating a new project and have a class called Repository that gathers info about the system the code is running on and makes some api requests. If the class has several internal values like system status which is fetched from an api, should I run the code to fetch the status in the constructor or can I have a property getter so I can write repo.system_status to get the latest value without needing to call a function ?
8 replies
NNuxt
Created by Jacko on 7/5/2024 in #❓・help
what’s the difference between antfu/eslint config vs the eslint plugin ?
I’ve seen both recommended so I’m unsure what the difference is
2 replies
NNuxt
Created by Jacko on 7/5/2024 in #❓・help
Is there a recommended way to start a nuxt project ?
So I just finished learning the basics of Vue and want to start a new website using nuxt. I’m confused though that when I use vue create it seems very opinionated and does a lot of the hard work like prettier and eslint configuration and creating a full directory structure for a demonstration. Is there a similar way to start nuxt, as the default method seems very barebones ?
2 replies