julian
julian
CC#
Created by julian on 1/26/2024 in #help
EF Error when adding migration
I'm getting this error:
No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
I have defined this in the program.cs
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
This is my ApplicationDbContext.cs
public ApplicationDbContext(DbContextOptions options) : base(options) { }
public ApplicationDbContext(DbContextOptions options) : base(options) { }
16 replies
CC#
Created by julian on 12/12/2023 in #help
Error on activation
Class I'm trying to activate
public class SwaggerGenConfigureOptions : IConfigureOptions<SwaggerGenOptions>
{
private readonly IApiVersionDescriptionProvider _provider;

public SwaggerGenConfigureOptions(IApiVersionDescriptionProvider provider) => _provider = provider;

public void Configure(SwaggerGenOptions options)
{
foreach (var description in _provider.ApiVersionDescriptions)
{
options.SwaggerDoc(description.GroupName, new OpenApiInfo()
{
Title = "XXXXXXX Domain API",
Version = description.ApiVersion.ToString(),
Description = "API to read and change data in the Absence Domain" + (description.IsDeprecated ? " (deprecated)" : ""),
});
}
}
}
public class SwaggerGenConfigureOptions : IConfigureOptions<SwaggerGenOptions>
{
private readonly IApiVersionDescriptionProvider _provider;

public SwaggerGenConfigureOptions(IApiVersionDescriptionProvider provider) => _provider = provider;

public void Configure(SwaggerGenOptions options)
{
foreach (var description in _provider.ApiVersionDescriptions)
{
options.SwaggerDoc(description.GroupName, new OpenApiInfo()
{
Title = "XXXXXXX Domain API",
Version = description.ApiVersion.ToString(),
Description = "API to read and change data in the Absence Domain" + (description.IsDeprecated ? " (deprecated)" : ""),
});
}
}
}
Activation:
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, SwaggerGenConfigureOptions>();
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, SwaggerGenConfigureOptions>();
Error: Error msg was too long to be posted here. https://pastebin.com/x0NsubVB
1 replies
CC#
Created by julian on 11/23/2023 in #help
Backend For Frontend Deployment on Azure
Anyone got experience deploying a Backend For Frontend Project (Vue.js with ASP.NET Core) on Azure? Would love to be guided through it. I'm really new to azure.
1 replies
CC#
Created by julian on 10/13/2023 in #help
Not able to run .NET apps
No description
3 replies
CC#
Created by julian on 10/13/2023 in #help
❔ dotnet publish docker fails
No description
11 replies
CC#
Created by julian on 10/10/2023 in #help
❔ Docker: Dotnet restore just loading
This is my Dockerfile. It's installing all the node_modules and build is doing fine, but on dotnet restore, it's just loading. Why?
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# ---- Vue.js Build Stage ----
FROM node:16-alpine AS build-vue
WORKDIR /app

# Copy package.json and yarn.lock for yarn install
COPY BFF/clientapp/package.json BFF/clientapp/yarn.lock ./
RUN yarn install

# Copy the rest of the Vue.js app and build it
COPY BFF/clientapp/ .
RUN yarn build

# .NET stages
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["BFF/BackendForFrontend.csproj", "BFF/"]
COPY ["Workcruit.Recruiter.WebClient.Grains/Workcruit.Recruiter.WebClient.Grains.csproj", "Workcruit.Recruiter.WebClient.Grains/"]
RUN dotnet restore "BFF/BackendForFrontend.csproj"
COPY . .
WORKDIR "/src/BFF"

# Copy the built Vue.js files to the appropriate directory in the .NET project
COPY --from=build-vue /app/dist ./wwwroot

RUN dotnet build "BackendForFrontend.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "BackendForFrontend.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BackendForFrontend.dll"]
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# ---- Vue.js Build Stage ----
FROM node:16-alpine AS build-vue
WORKDIR /app

# Copy package.json and yarn.lock for yarn install
COPY BFF/clientapp/package.json BFF/clientapp/yarn.lock ./
RUN yarn install

# Copy the rest of the Vue.js app and build it
COPY BFF/clientapp/ .
RUN yarn build

# .NET stages
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["BFF/BackendForFrontend.csproj", "BFF/"]
COPY ["Workcruit.Recruiter.WebClient.Grains/Workcruit.Recruiter.WebClient.Grains.csproj", "Workcruit.Recruiter.WebClient.Grains/"]
RUN dotnet restore "BFF/BackendForFrontend.csproj"
COPY . .
WORKDIR "/src/BFF"

# Copy the built Vue.js files to the appropriate directory in the .NET project
COPY --from=build-vue /app/dist ./wwwroot

RUN dotnet build "BackendForFrontend.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "BackendForFrontend.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BackendForFrontend.dll"]
35 replies
CC#
Created by julian on 10/1/2023 in #help
✅ Contracts.dll for Domain not being activated
Hi, I'm trying out to build a Domain project where I have a Contracts project, that will have the interfaces (and logics) used in the Webclient. I'm getting this error: System.InvalidOperationException: Unable to resolve service for type 'Workcruit.Domain.Contracts.Interfaces.ITestInterface' while attempting to activate 'BackendForFrontend.Controllers.AuthController'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired) at lambda_method8(Closure, IServiceProvider, Object[]) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>cDisplayClass6_0.<CreateControllerFactory>gCreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>gAwaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>gLogged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>gLogged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>gAwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context) My code in the Domain:
ITest.cs
namespace Workcruit.Domain.Contracts.Interfaces
{
public interface ITestInterface
{
Task<string> Test();
}
}

Test.cs
public class Test : Contracts.Interfaces.ITestInterface
{
Task<string> ITestInterface.Test()
{
return Task.FromResult("Test");
}
}

Program.cs
public class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Workcruit.Domain");
try
{
Console.WriteLine("Starting Workcruit.Domain...");
await Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<HostService>();
services.AddScoped<Contracts.Interfaces.ITestInterface, Workcruit.Domain.Services.Test>();
})
.RunConsoleAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
ITest.cs
namespace Workcruit.Domain.Contracts.Interfaces
{
public interface ITestInterface
{
Task<string> Test();
}
}

Test.cs
public class Test : Contracts.Interfaces.ITestInterface
{
Task<string> ITestInterface.Test()
{
return Task.FromResult("Test");
}
}

Program.cs
public class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Workcruit.Domain");
try
{
Console.WriteLine("Starting Workcruit.Domain...");
await Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<HostService>();
services.AddScoped<Contracts.Interfaces.ITestInterface, Workcruit.Domain.Services.Test>();
})
.RunConsoleAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
Code in the WebClient:
public AuthController(Workcruit.Domain.Contracts.Interfaces.ITestInterface testInterface)
{
_testInterface = testInterface;
}

public async Task<ActionResult> Test()
{
string test = await _testInterface.Test();
return Ok(test);
}
public AuthController(Workcruit.Domain.Contracts.Interfaces.ITestInterface testInterface)
{
_testInterface = testInterface;
}

public async Task<ActionResult> Test()
{
string test = await _testInterface.Test();
return Ok(test);
}
Getting the error written at the top of this thread.
41 replies
CC#
Created by julian on 8/3/2023 in #help
❔ ASP.NET Core Web API with Auth0
So, I’ve been working on a project for about 8 months now, and was thinking of changing the Authentication system from my own written to Auth0, but how would It work with ASP.NET Core Web API? Is it possible to have a /api/login endpoint, that redirects to auth0’s login page, and returns a token If successfully logged in?
5 replies
CC#
Created by julian on 5/21/2023 in #help
✅ Scoped, Singleton and HostedService
Any .NET Masters here? xD Issue: I'm trying to create a new Background Service for automatic selling/buying crypto (It's a school project, so no real trading/money involved). I'm having issues with the activation of the repo/services etc. I'm adding the Repo to my Service, which has EF Core (Repo). It has Scoped on the Repository classes. When I try to add the Service as a Singleton and my background service as a HostedService, I just get an error that It can not activate. I'm using ASP.NET Core Web API Any work arounds? I've tried posting in the DotNetEvolution, but didn't get any response.
96 replies