❔ Startup File to Program file
I watched a tutorial video where the code above was called in the Startup.vsmean while I only have a Program.cs . Is there a way I can call this in Program.cs
68 Replies
short answer: yes
it's code
you can call whatever code you want in code that you write
it's called writing code
long answer:
that's presumably a snippet of setup code for the
Microsoft.Extensions.DependencyInjection
library
where services
is an IServiceCollection
if you're building something like ASP.NET or something based on Microsoft.Extensions.Hosting
or maybe a MAUI app
the app framework already has an IoC/DI container, you just need to configure it
as an examplebuilder.Services.AddTransient etc
this would essentially be your
Main()
method
if you're not using something like this, you can still use the MS.E.DI library, you just have to set it up yourself
This didn't work
can you show how your program.cs looks? @dlaw_code
Ok. In a jiffy
oh, what doesnt work? you are already doing the same thing with the AddSingleton<>. Just put in this code after the addsingleton call:
I put it but it's bringing error
Ok, but this has nothing do to with the difference between startup.cs and program.cs. You are just missing some import statements and/or nuget package references. what tutorial are you following?
Tim Corey
What nuget package reference do you think am missing
that's a youtube channel, what tutorial are you following?
not shure tbh, i cant find anything that has and IContactData Interface. is this an interface that you have created?
Yeah
I thought maybe it's cos he's using an older version of .NET Cos am working with .Net 6
if you have defined the interface and class, then this shouldn't make a difference
you just need do add a using statement
I thought so too
Now i have no idea of what using statement i can use
in what namespace is the interface defined?
Those seem to be self-created types, not library provided
yes, thats why i am trying to find out in what namespace the types are
Ctrl+T, type "IContactData"
select first hit. check namespace.
so in your program.cs
using DataAccessLibrary;
you need to have a reference to that project, if they are different projects (which I assume they are)This is what it brought
The entire purpose of that was to find IContactData and check the namespace
something you already did 8 minutes ago :p
Lol. Am sorry. Didn't get that
???
???
What should i do next?
Did you add the
using
statement to program.cs?U mean the
yes.
Yeah i did but it didn't work
"didn't work" doesnt help me at all
what exactly do you mean by that
Im sure VS is giving you some errors
I mean it brought error
So show the errors.
I cant see your screen
hm, this seems odd
your
Program
class isnt in a namespace
thats.... very unusual
also, I think you are missing a project referenceso add the missing
;
then we add the project referenceI added it. Stil the same thing
How do i add the project reference
find your project in the solution explorer
expand "dependencies" and right click it
then do "add project reference"
Ok. In a jiffy
This is what brought. Is it the one?
yep
check that box.
then click ok
Your program is split in multiple projects, and they are not by default aware of eachother
Ok
I have done that. What's next?
your problem should now be solved.
still showing
open your .csproj for the blazor project
show content
How do i locate that
its your project file
Ok
u mean this?
yes, doubleclick that
should open it as text
U mean this?
your project reference wasnt saved
did you press cancel :p
Nah
If you say so
but the fact is that it wasnt saved.
¯\_(ツ)_/¯
How do i save it?
by clicking the "OK" button after checking the box
I have done that already
If you say so.
but from what I can see, the project reference was not saved
Am confused bro with the project
I can see that. I think you've been moving a bit too fast in your ambition and should repeat the basics a bit more
Okies Bro. Thanks. I would just take my time to go through the project again and see where the error is coming from.
Thanks for the help anyways
best of luck.
Bro. I figured it out Already
Great. What was it?
I moved the Sqldata and the Contactdata class into the Data folder
But i encountered another error someplace again🙁
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.