Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
Update README.md --nobuild
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Bickel <96277815+Ch0pstix@users.noreply.github.com>

Update README.md --nobuild

Signed-off-by: Isaac Bickel <96277815+Ch0pstix@users.noreply.github.com>

Update README.md --nobuild

Signed-off-by: Isaac Bickel <96277815+Ch0pstix@users.noreply.github.com>

Update README.md --nobuild

Update README.md --nobuild

Update README.md --nobuild

Update README.md --nobuild

Update README.md --nobuild

Update README.md --nobuild

Update README.md

Update README.md

Update README.md

Update README.md

Update README.md

Update README.md

Update README.md --nobuild

Signed-off-by: Isaac Bickel <96277815+Ch0pstix@users.noreply.github.com>

Update README.md --nobuild

Signed-off-by: Isaac Bickel <96277815+Ch0pstix@users.noreply.github.com>

Update README.md --nobuild

Signed-off-by: Isaac Bickel <96277815+Ch0pstix@users.noreply.github.com>
  • Loading branch information
Ch0pstix committed Feb 12, 2023
1 parent 4bdaa15 commit 5d42c1c
Showing 1 changed file with 82 additions and 49 deletions.
131 changes: 82 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,91 @@
# InjectX · ![License](https://img.shields.io/github/license/Ch0pstix/InjectX?style=flat-square)
![InjectX Banner][1]
![Build Workflow Status - Master][2] ![CodeQL Workflow Status - Master][3]

![InjectX Banner](/res/banner.png?raw=true)
# What is InjectX? 🔎

Automatic service registration extensions for `Microsoft.Extensions.DependencyInjection`.
The **InjectX** and **InjectX.Mvvm** libraries were developed with the aim of simplifying the implementation of dependency injection in your .NET applications. They achieve this by eliminating the need to register services, and in the case of **InjectX.Mvvm**, views and viewmodels, individually with the service container.

## 🚀 Getting Started
This is made possible by adding [a few helpful extensions][4] to the `IServiceCollection` class from Microsoft's dependency injection library, [Microsoft.Extensions.DependencyInjection.][5]

The packages may be installed via Nuget, Package Manager Console, or DotNet CLI.

### Nuget
# Getting started 🚀

- [InjectX][1]
> **Note**: The dev prefix **Ch0pstix.\*** is added to the package IDs as a means of avoiding naming conflicts with some unlisted packages in the NuGet catalog. This prefix is not present in the namespaces of the actual libraries.
![Version](https://img.shields.io/nuget/v/InjectX?label=Version&style=flat-square) ![Downloads](https://img.shields.io/nuget/dt/InjectX?label=Downloads&style=flat-square)
The packages may be installed via nuget, package manager console, or dotnet cli.

- [InjectX.Mvvm][2]
### NuGet

- [Ch0pstix.InjectX][6]

![Version](https://img.shields.io/nuget/v/InjectX.Mvvm?label=Version&style=flat-square) ![Downloads](https://img.shields.io/nuget/dt/InjectX.Mvvm?label=Downloads&style=flat-square)
![Ch0pstix.InjectX Nuget Version][7] ![Ch0pstix.InjectX Nuget Downloads][8]

[1]: https://www.nuget.org/packages/InjectX/
[2]: https://www.nuget.org/packages/InjectX.Mvvm/
- [Ch0pstix.InjectX.Mvvm][9]

![Ch0pstix.InjectX.Mvvm Nuget Version][10] ![Ch0pstix.InjectX.Mvvm Nuget Downloads][11]

### Package Manager Console

```shell
Install-Package InjectX
Install-Package InjectX.Mvvm
Install-Package Ch0pstix.InjectX
Install-Package Ch0pstix.InjectX.Mvvm
```

### DotNet CLI

```shell
dotnet add package InjectX
dotnet add package InjectX.Mvvm
dotnet add package Ch0pstix.InjectX
dotnet add package Ch0pstix.InjectX.Mvvm
```

## 📂 What's Included

# What's included 📂

### Types

| Name | Description |
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| [SingletonAttribute](src/InjectX.Shared/SingletonAttribute.cs) | Specifies that a view or service should be registered with a `ServiceLifetime` of `ServiceLifetime.Singleton`. |
| [TransientAttribute](src/InjectX.Shared/TransientAttribute.cs) | Specifies that a view or service should be registered with a `ServiceLifetime` of `ServiceLifetime.Transient`. |
| [ScopedAttribute](src/InjectX.Shared/ScopedAttribute.cs) | Specifies that a service should be registered with a `ServiceLifetime` of `ServiceLifetime.Scoped`. |
| [RegistrationStrategy](src/InjectX/RegistrationStrategy.cs) | Specifies strategies that may be applied when adding a `ServiceDescriptor` to an `IServiceCollection`. |
| Name | Description |
| :------------------------- | :------------------------------------------------------------------------------------------------------------- |
| [RegistrationStrategy][12] | Specifies strategies that may be applied when adding a `ServiceDescriptor` to an `IServiceCollection`. |

### Extensions

| Method | Description |
| :-------------------------------- | :--------------------------------------------------------------------------------------------- |
| [RegisterApplicationServices][13] | Registers service objects that have been defined within the application's assembly. |
| [RegisterAssemblyServices][13] | Registers service objects that have been defined within the specified assembly. |
| [RegisterViewsAndViewModels][14] | Registers view and viewmodel objects that have been defined within the application's assembly. |

### Extension Methods
### Attributes

| Method | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| [IServiceCollection.RegisterApplicationServices(optional: ServiceRegistrationStrategy)](src/InjectX/ServiceCollectionExtensions.cs) | Registers service objects that have been defined within the application's assembly. |
| [IServiceCollection.RegisterAssemblyServices(Assembly, optional: ServiceRegistrationStrategy)](src/InjectX/ServiceCollectionExtensions.cs) | Registers service objects that have been defined within the specified assembly. |
| [IServiceCollection.RegisterViewsAndViewModels()](src/InjectX.Mvvm/ServiceCollectionExtensions.cs) | Registers view and viewmodel objects that have been defined within the application's assembly. |
| Name | Description |
| :------------------------- | :------------------------------------------------------------------------------------------------------------- |
| [SingletonAttribute][15] | Specifies that a view or service should be registered with a `ServiceLifetime` of `ServiceLifetime.Singleton`. |
| [TransientAttribute][16] | Specifies that a view or service should be registered with a `ServiceLifetime` of `ServiceLifetime.Transient`. |
| [ScopedAttribute][17] | Specifies that a service should be registered with a `ServiceLifetime` of `ServiceLifetime.Scoped`. |

## 💡 Usage Examples

### Console App (InjectX)
# Usage examples 🪄

## Console App (InjectX)

#### Setting up the application service provider:

#### MyConsoleApp/Program.cs
```csharp
using MyConsoleApp.Services;

var services = new ServiceCollection()
.RegisterApplicationServices() // from MyConsoleApp.Services*
.RegisterApplicationServices() // from MyConsoleApp.Services
.BuildServiceProvider();

var service = services.GetRequiredService<IExampleService>();

service.SayHello();
```

#### MyConsoleApp/Services/IExampleService.cs
```csharp
public interface IExampleService()
{
void SayHello();
}
```
#### Setting a service's lifetime via lifetime annotation:

#### MyConsoleApp/Services/ExampleService.cs
```csharp
[Transient] // Compiled descriptor will be (IExampleService, ExampleService, ServiceLifetime.Transient)
[Transient] // Defaults to transient anyways when not provided.
public class ExampleService : IExampleService
{
public void SayHello()
Expand All @@ -91,19 +95,18 @@ public class ExampleService : IExampleService
}
```

---
## Wpf Mvvm App (InjectX + InjectX.Mvvm)

### Wpf Mvvm App (InjectX + InjectX.Mvvm)
#### Setting up the application service provider:

#### MyWpfApp/App.xaml.cs:
```csharp
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
var services = new ServiceCollection()
.RegisterApplicationServices() // from MyWpfApp.Services*
.RegisterViewsAndViewModels() // from MyWpfApp.Views* && MyWpfApp.ViewModels*
.RegisterApplicationServices() // from MyWpfApp.Services
.RegisterViewsAndViewModels() // from MyWpfApp.Views && MyWpfApp.ViewModels
.BuildServiceProvider();

var mainWindow = services.GetRequiredService<MainWindow>();
Expand All @@ -115,9 +118,10 @@ public partial class App : Application
}
```

#### MyWpfApp/Views/Dialogs/MyCustomDialogWindow.cs:
#### Overriding a view's lifetime via lifetime annotation:

```csharp
[Transient] // Override the default singleton lifetime as dialogs tend to be reusable objects
[Transient] // Override the default singleton lifetime (for views inheriting Window) since dialogs tend to be reused
public partial class MyCustomDialogWindow : Window
{
public MyCustomDialogWindow()
Expand All @@ -126,3 +130,32 @@ public partial class MyCustomDialogWindow : Window
}
}
```


# License 📄

**InjectX and related libraries** are free and open source software under the **MIT License**. This license permits the modification, distribution, and private and commercial use of this software. Keep in mind that you must include a copy of this license in your projects.

[View LICENSE.txt][18]


<!-- References -->

[1]: res/banner.png?raw=true
[2]: https://img.shields.io/github/actions/workflow/status/Ch0pstix/InjectX/build-master.yml?branch=master&label=build&logo=github&style=flat-square
[3]: https://img.shields.io/github/actions/workflow/status/Ch0pstix/InjectX/codeql-master.yml?branch=master&label=codeQL&logo=github&style=flat-square
[4]: #extensions
[5]: https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection
[6]: https://www.nuget.org/packages/Ch0pstix.InjectX/
[7]: https://img.shields.io/nuget/v/Ch0pstix.InjectX?label=version&logo=nuget&style=flat-square
[8]: https://img.shields.io/nuget/dt/Ch0pstix.InjectX?logo=nuget&style=flat-square
[9]: https://www.nuget.org/packages/Ch0pstix.InjectX.Mvvm/
[10]: https://img.shields.io/nuget/v/Ch0pstix.InjectX.Mvvm?label=version&logo=nuget&style=flat-square
[11]: https://img.shields.io/nuget/dt/Ch0pstix.InjectX.Mvvm?logo=nuget&style=flat-square
[12]: src/InjectX/RegistrationStrategy.cs
[13]: src/InjectX/ServiceCollectionExtensions.cs
[14]: src/InjectX.Mvvm/ServiceCollectionExtensions.cs
[15]: src/InjectX.Shared/SingletonAttribute.cs
[16]: src/InjectX.Shared/TransientAttribute.cs
[17]: src/InjectX.Shared/ScopedAttribute.cs
[18]: LICENSE.txt

0 comments on commit 5d42c1c

Please sign in to comment.