Click here to Skip to main content
15,886,873 members
Home / Discussions / WPF
   

WPF

 
Question[Solved/Workaround] Floating progress visualization with button control Pin
Evilfish20009-Aug-23 23:28
Evilfish20009-Aug-23 23:28 
AnswerRe: Floating progress visualization with button control Pin
Richard Deeming10-Aug-23 0:26
mveRichard Deeming10-Aug-23 0:26 
GeneralRe: Floating progress visualization with button control Pin
Evilfish200010-Aug-23 0:47
Evilfish200010-Aug-23 0:47 
AnswerRe: Floating progress visualization with button control Pin
Gerry Schmitz10-Aug-23 6:11
mveGerry Schmitz10-Aug-23 6:11 
QuestionWPF EF Core 6 DP Question Pin
Kevin Marois24-Jul-23 14:42
professionalKevin Marois24-Jul-23 14:42 
AnswerRe: WPF EF Core 6 DP Question Pin
Richard Deeming24-Jul-23 21:36
mveRichard Deeming24-Jul-23 21:36 
GeneralRe: WPF EF Core 6 DP Question Pin
Kevin Marois25-Jul-23 8:10
professionalKevin Marois25-Jul-23 8:10 
GeneralRe: WPF EF Core 6 DP Question Pin
Richard Deeming25-Jul-23 21:41
mveRichard Deeming25-Jul-23 21:41 
Add it as a constructor parameter.

Or are you saying that the ApplicationSecurity is defined in an assembly which doesn't have a reference to the assembly where the MooseDBContext is defined?

If that's the case, then you probably want the context to implement an interface:
C#
// ApplicationSecurity assembly:
public interface IApplicationSecurityContext
{
    DbSet<YourEntityType> YourEntityTypes { get; }
}

public class ApplicationSecurity : IApplicationSecurity
{
    public ApplicationSecurity(IApplicationSecurityContext context)
    {
        ArgumentNullException.ThrowIfNull(context);
        Context = context;
    }
    
    private IApplicationSecurityContext Context { get; }
    ...
}

// MooseDBContext assembly:
public class MooseDBContext : DbContext, IApplicationSecurityContext
{
    ...
}
Then register the interfaces as services:
C#
services.AddDbContext<MooseDBContext>(options =>
{
    options.UseSqlServer(_connString);
});

// When we request the IApplicationSecurityContext service,
// return the registered MooseDBContext service:
services.AddScoped<IApplicationSecurityContext>(sp => sp.GetRequiredService<MooseDBContext>());

You could even create a utility method to automatically register all interfaces implemented by your context:
C#
public static IServiceCollection AddContextInterfaces<TContext>(this IServiceCollection services) where TContext : DbContext
{
    ArgumentNullException.ThrowIfNull(services);
    
    foreach (Type t in typeof(TContext).GetInterfaces().Except(typeof(DbContext).GetInterfaces()))
    {
        services.AddScoped(t, sp => sp.GetRequiredService<TContext>());
    }
    
    return services;
}

...

services.AddDbContext<MooseDBContext>(options =>
{
    options.UseSqlServer(_connString);
});

services.AddContextInterfaces<MooseDBContext>();




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: WPF EF Core 6 DP Question Pin
Kevin Marois27-Jul-23 19:27
professionalKevin Marois27-Jul-23 19:27 
GeneralRe: WPF EF Core 6 DP Question Pin
Richard Deeming30-Jul-23 21:55
mveRichard Deeming30-Jul-23 21:55 
QuestionWPF xceed CheckcComboBox SelectAll Text Pin
Kevin Marois20-Jun-23 18:17
professionalKevin Marois20-Jun-23 18:17 
AnswerRe: WPF xceed CheckcComboBox SelectAll Text Pin
Richard Deeming20-Jun-23 20:53
mveRichard Deeming20-Jun-23 20:53 
GeneralRe: WPF xceed CheckcComboBox SelectAll Text Pin
Kevin Marois21-Jun-23 10:32
professionalKevin Marois21-Jun-23 10:32 
QuestionList of Images Pin
Kevin Marois9-Jun-23 13:47
professionalKevin Marois9-Jun-23 13:47 
QuestionChange Image URL's Assembly At Runtime Pin
Kevin Marois6-Jun-23 7:15
professionalKevin Marois6-Jun-23 7:15 
AnswerRe: Change Image URL's Assembly At Runtime Pin
Gerry Schmitz6-Jun-23 15:52
mveGerry Schmitz6-Jun-23 15:52 
Questionc# Spotify API not returning correctly. Pin
elfenliedtopfan52-Jun-23 18:03
elfenliedtopfan52-Jun-23 18:03 
AnswerRe: c# Spotify API not returning correctly. Pin
Pete O'Hanlon4-Jun-23 8:42
mvePete O'Hanlon4-Jun-23 8:42 
AnswerRe: c# Spotify API not returning correctly. Pin
jschell5-Jun-23 5:01
jschell5-Jun-23 5:01 
QuestionNeed help please regarding your awesome WPF MultiComboBox project :) Pin
Member 1160463425-May-23 5:21
Member 1160463425-May-23 5:21 
AnswerRe: Need help please regarding your awesome WPF MultiComboBox project :) Pin
jeron125-May-23 5:50
jeron125-May-23 5:50 
AnswerRe: Need help please regarding your awesome WPF MultiComboBox project :) Pin
Richard Deeming25-May-23 21:28
mveRichard Deeming25-May-23 21:28 
QuestionNavigationControl - Part 3 Pin
Kevin Marois14-May-23 8:01
professionalKevin Marois14-May-23 8:01 
AnswerRe: NavigationControl - Part 3 Pin
Richard Deeming14-May-23 21:40
mveRichard Deeming14-May-23 21:40 
GeneralRe: NavigationControl - Part 3 Pin
Kevin Marois15-May-23 17:14
professionalKevin Marois15-May-23 17:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.