extensions

Last updated:

0 purchases

extensions Image
extensions Images
Add to Cart

Description:

extensions

A set of APIs for commonly used programming patterns and utilities, such as dependency injection, logging, and configuration.


Configuration #
import 'package:extensions/configuration.dart';

void main() {
var configurationBuilder = ConfigurationBuilder()
// Adds a memory collection to the configuration system.
..addInMemoryCollection(
<String, String>{
'Logging:LogLevel:Default': 'Warning',
}.entries,
);

var config = configurationBuilder.build();
print(config['Logging:LogLevel:Default']);
}
copied to clipboard
Dependency Injection #
import 'package:extensions/dependency_injection.dart';

void main() {
var serviceCollection = ServiceCollection();
serviceCollection.addSingleton<MyService>(
implementationInstance: MyService(),
);
var services = serviceCollection.buildServiceProvider();
var myService = services.getRequiredService<MyService>();
}
copied to clipboard
Logging #
package:extensions/logging.dart' provides a class [LoggerFactory][LoggerFactory] to create a [Logger`][Logger] for a specific category.
import 'package:extensions/logging.dart';

void main() {
LoggerFactory.create(
(builder) => builder
..addDebug()
..setMinimumLevel(LogLevel.debug),
).createLogger('MyLogger').logDebug('Hello World');
}
copied to clipboard
The preceeding code uses the [LoggerFactory] static method [create][LoggerFactory.create] to create a [Logger][Logger]. The output is displayed in the debug window and looks like this:
[MyLogger] LogLevel.debug: Hello World
copied to clipboard
Generic Host #
import 'package:extensions/hosting.dart'

Future<void> main(List<String> args) async =>
await Host.createDefaultBuilder(args)
.useConsoleLifetime()
.build()
.run();
copied to clipboard
Extensions is a derived work of the dotnet/runtime

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.