Dependous 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Dependous --version 1.0.0                
NuGet\Install-Package Dependous -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dependous" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dependous --version 1.0.0                
#r "nuget: Dependous, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Dependous as a Cake Addin
#addin nuget:?package=Dependous&version=1.0.0

// Install Dependous as a Cake Tool
#tool nuget:?package=Dependous&version=1.0.0                

Dependous

A lightweight cross platform dependency scanning library

Dependous grants you the power to insepct a collection of .NET assemblies and extract types implementing specific interfaces. That's it. Simple and easy.

Dependous eliminates the need to explictly describe different types of dependencies you wish to locate. Instead Dependeous allows you define your dependencies as you develop your classes with a "think about it once and forget about it" approach by employing discovery interfaces.

A discovery interface can be any .NET interface. Dependous implements three intefaces that are specific to IOC container lifetime management.

ITransientDependency Designates an implementor as a discoverable dependency and asserts it's lifetime management should be transient.

ISingletonDependency Designates an implementor as a discoverable dependency and asserts it's lifetime management should be singleton.

IScopedDependency Designates an implementor as a discoverable dependency and asserts it's lifetime management should be scoped.

ISelfTransient Makes a concrete type injectable through the IOC container and sets it's lifetime to trainsient

ISelfSingleton Makes a concrete type injectable through the IOC container and sets it's lifetime to singleton

These five interfaces only assert your intent on how instances of your dependency should be handled. This will be captured in the DependencyMetadata instance. It's up to the IOC container integration to actually register your dependencies.

When declaring discovery interfaces, you must bind it to a specific lifetime. Either Singleton, Transient or Scoped.

Examples

The Most Basic Scanning Example
var scanner     = DependencyScannerFactory.Create();
var scanResult = scanner.Scan((f) => f.StartsWith("MyAssembly"));
Register a concrete type
public class MyModel : ISelfTransient{
   
    public MyModel( ISomeDependency d){
    }
}

now you can inject MyModel wherever you please.
Adding Additional Discovery Interfaces
Action<IDependousConfiguration> configurationBuilder = (config) =>
{
  config.AddAdditionalDiscoveryTypes(d => d.RegisterType<IModule>(ServiceLifetime.Singleton)
                                           .RegisterType<IRegistrationSource>(ServiceLifetime.Singleton));
  configurationBuilder?.Invoke(config);
};
var scanner     = DependencyScannerFactory.Create();
var scanResult = scanner.Scan((f) => f.StartsWith("MyAssembly"),configurationBuilder );

In addition to the three default discovery interfaces, this example will register two additional discovery interfaces IModule and IRegistrationSource. Now when the scanner executes, any class implementing IModule or IRegistrationSource will be discovered as a dependency.

Using A Default Discovery Interface
public class MyService : IMyService, ISingletonDependency{
}

MyService will be discovered as a dependency with a lifetime of singleton.

Targeting a specific range of interfaces

By default, the assembly scanning will extract all interfaces implemented by your dependency. Often times this behavior is desirable; however, if you need to target a specific subset of interfaces, use this attribute.

 [Target(typeof(IInterface1))]
public class MyDependency : IInterface1, IInterface2, ITransientDependency{
}

MyDependency will be discovered but it's list of implemented interfaces will only contain IInterface1

Using Probing Paths For Plug-In based Architectures

By default, Dependous will only scan for assemblies located directly in your bin folder. If you wish to expand your search horizons, add your probing paths to the dependous configuration.

    var instance = DependencyScannerFactory.Create();
    var result = instance.Scan((b) => b.StartsWith("Dependous.Probing"), (c) => c.AddProbingPaths(pb => pb.AddProbingPath("../../../../../tests/Dependous.Probing/bin/Debug/netstandard2.0")));
    Assert.True(result.Metadata.Any());

Additionally, if you need to have a different assembly filter, you can pass it along with your probing path:

    var instance = DependencyScannerFactory.Create();
    var result = instance.Scan((b) => b.StartsWith("Dependous.Probing"), (c) => c.AddProbingPaths(pb => pb.AddProbingPath("../../../../../tests/Dependous.Probing/bin/Debug/netstandard2.0"),cb=>cb.StartsWith("Plugins")));
    Assert.True(result.Metadata.Any());
Accessing Dependous scan results

In some scenarios, you may want to inspect the collected dependcy metadata from a Dependous scan.

var scanner     = DependencyScannerFactory.Create();
var scanResult = scanner.Scan((f) => f.StartsWith("MyAssembly"),cb=>cb.PersistScanResults=true );
//Now you can inject the results into any class

public class MyService{
    public MyService(DependencyScanResult dependencyScanResults){
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Dependous:

Package Downloads
Dependous.AutoFac

A lightweight cross platform dependency scanning library Dependous grants you the power to insepct a collection of .NET assemblies and extract types implementing specific interfaces. That's it. Simple and easy. This package combines Dependous and an add-on for AutoFac container registration

Dependous.Microsoft.Extensions.DependencyInjection

Provides container registration for the default Microsoft IOC container.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.0 114 7/31/2024
7.0.7 260 5/21/2024
7.0.2 718 3/2/2023
7.0.1 523 2/6/2023
7.0.0 295 2/2/2023
6.0.0 805 1/21/2022
1.0.0 2,835 2/1/2021