nightooi /s I'm rarely serious
nightooi /s I'm rarely serious
CC#
Created by nightooi /s I'm rarely serious on 3/11/2024 in #help
DI in Asp.net core, abstract
I'm just now getting into the DI stuff in asp.net, I've used DI patterns before but only in xaml and windesktop stuff, and even then I never really understood it. Having gone over the docks thoroughly and many a time... I'm starting to get a grasp if you could help me confirm the things i've gathered. I'm in the process of writing a bigger piece of code based on this, I'll put it up in review channel once I'm done. things I've noticed: DI is basically a global Object with a bunch of predefined interfaces: With the service-collection implementation at app level you define a collection of interfaces which all other elements of your code "could" depend on and instead of passing the object around you pass around the interface you depend on. You then provide the implementation at app level and you're done, asp.net resolves the interface to the object dependency at runtime. The instantiation gets moved to startup.cs: With .net 8 startup.cs isn't a thing anymore, where you normally would run your singletons, factories and configurations which would have dependencies in the environment and change their implementation. Now it gets done in the appbuilder.Services.Add--(ConfigClass). In the config class you run your configs, which should be a jsonfile with configurations of the implementation. move of imperative/boilerplate code from application logic: Without DI you're stuck doing configuration logic for each object either in your razor page or your controller. Like when your model has dependencies in some other REST-client so you run the request in the controller, when all you really want to do is to have it populated with the data. To avoid this you move the population logic and request instantiation and response handling to your DI container, and in the controller you can just run the interface function. If i missed anything, or have some misconceptions type it please out 🙂
10 replies
CC#
Created by nightooi /s I'm rarely serious on 3/10/2024 in #help
Compiler optimizations with generics
c#
public interface Isome<T> where T: ISomeOther
{
T Foo();
}
//vs

public interface ISome
{
ISomeOther Bar();
}


public class A : ISome<SomeOther> //where SomeOther : ISomeOther
{
SomeOther Foo();
}
//vs

public class B : ISome
{
SomeOther Bar(); //where SomeOther : ISomeOther
}
c#
public interface Isome<T> where T: ISomeOther
{
T Foo();
}
//vs

public interface ISome
{
ISomeOther Bar();
}


public class A : ISome<SomeOther> //where SomeOther : ISomeOther
{
SomeOther Foo();
}
//vs

public class B : ISome
{
SomeOther Bar(); //where SomeOther : ISomeOther
}
Is the implementation of A and B semantically equivalent or is there some Boxing/Unboxing/polymorphism going on with the Implementation of B? Meaning that A would be more efficient Because of static compiler optimizations with generics?
2 replies
CC#
Created by nightooi /s I'm rarely serious on 1/28/2024 in #help
✅ What's a good strategy to load serverside resources into your controller?
Right now I have a few images and videos that so far i've been loading to views using Directory calls. I was thinking it's about time i start doing some caching. Im just thinking I wouldnt want the directory/file stack to be linked to the controller at all, feels like it's not the place for it. So what's a good approach to loading static resources like images/videos/etc?
10 replies
CC#
Created by nightooi /s I'm rarely serious on 1/24/2024 in #help
✅ Takewhile in foreach iterator exiting without iterating over the elements.
foreach(var i in this.SomeDict<string, object>.Keys.TakeWhile(x => x.Conains("somestring"))) { //do work. } i know for a fact that there are string containing "somestring". During debugging the debugger just stepps into the TakeWhile, returns twice to dict, goes into in once and then just skips the inner block. The I variable is being resolved to a string, and the result of the takewhile is a ienumerable, so why does it skip iterating over the returned elements?
4 replies
CC#
Created by nightooi /s I'm rarely serious on 1/23/2024 in #help
✅ Can't access attributes from view in helpertag.
No description
2 replies
CC#
Created by nightooi /s I'm rarely serious on 1/19/2024 in #help
✅ Possible bug in ternary operator when incrementing in razorpages?
inside some .cshtml: @{ int a; int k; if(Model.SomeArray != null) { a = Model.SomeArray[0].SomeIndex; } for(int i=0; i<Model.SomeOtherArray.Length; i++) { if(i==a) { //do somework k = (k+1 < Model.SomeArray.Length) ? k++ : k; } } } correct me if im wrong but k should increment here and then be saved? or is the ternary operator scope localized and the parameter get incremented in another scope and the obj ref then dropped, meaning that the work is lost? in razor pages k++, or even k=k++; doesnt update the object. k=k+1 works though. This should be a bug right?
6 replies
CC#
Created by nightooi /s I'm rarely serious on 1/19/2024 in #help
is there a override for when a given type is being instanced as an array?
Im wondering if i can inject some logic if a type is being instanced as an array. say a class A. is being instanced as array, i want inject a sorting algorithm without depending on the user to run a member function or have something like a factory for the object creation
6 replies